Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The two things to keep in mind when making an admin area are 1) you can create namespaces for routes to get the /admin URLs you're looking for and 2) you can have controllers inherit from other descendants of ActionController</p> <p>So to make an admin area, you'd want to have RESTful resources declared in a namespace (assumes Rails 3 routes):</p> <pre><code># routes.rb resources :users resources :posts resources :pages namespace :admin do |admin| match '/' =&gt; 'dashboard#index' resources :users resources :posts resources :pages end </code></pre> <p>The top set is the public ones and the bottom set gives you the admin routes like /admin/users/new and /admin/posts/1, etc. I'm also assuming you might want a "dashboard" so I'm setting up a route to the index method of an Admin::DashboardController</p> <p>Then you create an admin base controller that descends from ApplicationController. Use it to hold your admin area layout and your authentication filters:</p> <pre><code>class Admin::BaseController &lt; ApplicationController before_filter :require_user layout 'admin' end </code></pre> <p>Now make a directory in app/controllers called "admin". Make controllers in there as normal, but have them inherit from your base controller:</p> <pre><code># pages_controller.rb class Admin::PagesController &lt; Admin::BaseController # Controller code in here end </code></pre> <p>Make a corresponding directory in app/views for "admin" and you're good to go -- everything is namespaced out and views/controllers would behave like you think.</p> <p>You can always run "rake routes" to see all the admin routes.</p> <p>Hope that helps!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload