Backend administration in Ruby on Rails

柔情痞子 提交于 2019-11-27 16:44:22
Laurie Young

I think namespaces is the solution to the problem you have here:

map.namespace :admin do |admin|
    admin.resources :customers
end

Which will create routes admin_customers, new_admin_customers, etc.

Then inside the app/controller directory you can have an admin directory. Inside your admin directory, create an admin controller:

./script/generate rspec_controller admin/admin

class Admin::AdminController < ApplicationController

  layout "admin"
  before_filter :login_required
end

Then create an admin customers controller:

./script/generate rspec_controller admin/customers

And make this inhert from your ApplicationController:

class Admin::CustomersController < Admin::AdminController

This will look for views in app/views/admin/customers and will expect a layout in app/views/layouts/admin.html.erb.

You can then use whichever plugin or code you like to actually do your administration, streamline, ActiveScaffold, whatever personally I like to use resourcecs_controller, as it saves you a lot of time if you use a REST style architecture, and forcing yourself down that route can save a lot of time elsewhere. Though if you inherited the application that's a moot point by now.

phoet

Do check out active_admin at https://github.com/gregbell/active_admin.

I have used Streamlined pretty extensively.

To get Streamline working you create your own controllers - so you can actually run it completely apart from the rest of your application, and you can even run it in a separate 'admin' folder and namespace that can be secured with .

Here is the Customers controller from a recent app:

class CustomersController < ApplicationController
  layout 'streamlined'
  acts_as_streamlined       

  Streamlined.ui_for(Customer) do
    exporters :csv   
    new_submit_button :ajax => false 
    default_order_options :order => "created_at desc"   
    list_columns :name, :email, :mobile, :comments, :action_required_yes_no  
  end
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!