Administer Rails models data


(Will) #1

Is it possible to administer regular rails data using push_types interface?


(Aaron Russell) #2

Yes. There’s a few things you need to do but basically you can create your own controller, inherit from PushType’s admin controller (which will use PushType’s authentication and render any views in the admin layout) and you can edit the main menu to insert a link to your controller.

Say you have a Widget resource, I’d approach it something like this.

# Generate your controller
rails g controller admin/widgets

Your controller should inherit from PushType::AdminController.

class Admin::WidgetsController < PushType::AdminController
  # your own code
end

Add the routing.

# in config/routes.rb
namespace :admin do
  resources :widgets
end

Finally, add a link to the admin main menu.

# in config/application.rb
config.after_initialize do
  PushType.menu(:main) do
    item :widgets do
      link    { main_app.admin_widgets_path }
      active  { request.fullpath.match %r{admin/widgets} }
    end
  end
end

Then restart your application.


(Will) #3

Great! that makes it possible to use with our regular rails apps.

Should i declare the usual “field :description” code per field i want to expose in the PT admin?

I really really like what you have done so far on this with fields. Especially the Matrix, reminds me of Statamic, which is always a good thing.

W


(Will) #4

Oh actually, i get an error trying that out. I get a widgets menu item, but when i click into it:

vendor/bundle/gems/push_type_core-0.10.4/app/controllers/front_end_controller.rb:41:in `raise_404’

Looking at the line raising that:
https://github.com/pushtype/push_type/blob/master/core/app/controllers/front_end_controller.rb#L29

It’s because it’s not a node. is there a known workaround / any hints what I’m missing?

btw, how cool is the github integration there? amazing.


(Aaron Russell) #5

I’m guess maybe the order of preference in routes.rb. Always make sure the mount_push_type line is the very last rule - so the custom admin rule above comes before it.

No, what I’ve described above assumes you’ve got your own model with it’s own data attributes defined through normal rails migrations. There’s no magic going on here so you need to write your own controllers, views etc.


(Will) #6

oh ok, got it. Ill try and work through that for an example model. Maybe this could be strengthened in the future with a rake task to generate the admin parts needed to get going with a regular model? I can’t imagine a rails project where i wouldn’t need this.


(Petros) #7

I tried that and I had to manually scaffold the views (using the Rails generators) in order to act upon the CRUD operations. Is this how it supposed to be, as aesthetically it lacks consistency with the rest of the dashboard menu items’ views, it different markup after all.

I guess the cleanest solution would be a generator; if there is any advice about the minimal set of attributes required to scaffold an arbitrary Rails model in the Dashboard – model’s attributes excluded of course --, I might give it a shot. It will make a difference in the workflow.

For the time being however, in order to have any resource integrated to PUSHTYPE's admin dashboard, you just need to scaffold it using the vanilla Rails generators (e.g. rails g scaffold admin/notification), change the inheritance directive in the controller and populate the menu link.

Thanks for this project, the most comprehensive open-source Rails CMS solution!


(Aaron Russell) #8

Yes, all the solution above does is allow you to create a controller that is authenticated with PushType’s authentication, renders it’s views within the PushType layout, and add a link to the menu.

If you’ve used Rail’s scaffold generators, then you should do a bit of work to make your views visually more cohesive with PushType. There’s no documentation for how best to do this, but for now define markup using Foundation Sites 5 styles and components.

Of course, there is a new admin UI in the works, so some of the things we’re discussing in this thread will change (the new UI doesn’t use Foundation for a start). It’s months away from being ready so use this resource for now. I’ll try and post here closer to the time if things are going to change.