Rails Application Administration Section

I am working on my first Rails application and want to create an admin section.

I want my views and controllers to be completely separate (i.e. in separate directories) for the admin section and the rest of the site?

How can I arrange my views / controllers in user directories (how to configure routing)?

+7
ruby ruby-on-rails
source share
3 answers

You can also store applications and controllers in their usual places and use Rails filters to control access, which I think you're looking for here.

If you have an AWDWR Book, go to Chap11 Task F Administrivia

  • Basically define an authorization method in the application \ controllers \ application.rb, which checks the authorization, redirects to the login page, if not registered in et.all
  • Check the controllers you want to restrict access with before_filter s

.

 class AdminController < ApplicationController before_filter :authorize # ... the rest of the code end 

This will intercept all calls to actions defined in the AdminController and force them to go through authorization.

+5
source share

To create administrator controllers:

 script/generate controller admin/articles 

Then in the routes.rb file

 map.resource :admin do |admin| admin.resources :articles, :path_prefix => "admin", :name_prefix => "admin_", :controller => "admin/articles" end 

You can then access this URL:

 <%= link_to "Articles Admin", admin_articles_path %> 
+8
source share
 map.namespace :admin do |admin| admin.register :controller => 'main', :action => 'register' admin.login, :controller => 'main', action => 'login' # ... end 

Here's how you prescribe things, add this to the other comments here about authorizing things, and you leave. Take a look at the restful_authentication plugin to make your user management much faster and easier than minimizing your own.

The above routing assumes that the controllers and their views are in the admin subdirectory, which I think is what you want.

+5
source share

All Articles