Backend administration in Ruby on Rails

后端 未结 4 1776
盖世英雄少女心
盖世英雄少女心 2020-12-04 05:46

I\'d like to build a real quick and dirty administrative backend for a Ruby on Rails application I have been attached to at the last minute. I\'ve looked at activescaffold a

4条回答
  •  时光说笑
    2020-12-04 06:08

    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.

提交回复
热议问题