what the best rails way to do the following

I've rails 3 app which displays records from a DB into table. I want the same method to check if the admin controller is used and if so add edit delete options to the table items.

Example: logged in a none admin server/home/list_info

  • Some info name address
  • More info name address

Logged in as Admin sever/admin/list_info

  • Some info name address Edit Delete
  • More info name address Edit Delete

I've currently got two controllers and two view methods, the admin method is just a copy with the Edit Delete links on the end. This doesn't seem very DRY to me. What to people do in this situation ?

Many Thanks Andy


I think the best way is to have one set of controllers/views and simply see if the current user is an admin. If yes, show the edit/delete links.

Typically, you could use Devise for authentication and CanCan for authorization.

Devise provides a current_user object, so if you implement an admin? method you could use something like

<%= link_to_if current_user.admin?, 'Delete', ... %>

Note: the above uses only Devise, not CanCan.

Need Your Help

How to cache popular queries to avoid both stamedes and blank results

mysql caching memcached gearman

On the customizable front page of our web site, we offer users the option of showing modules showing recently updated content, choosing from well over 100 modules.

Is there a KeyUp: method for flagsChanged:?

objective-c nsresponder

I have implemented the - (void)flagsChanged:(NSEvent *)theEvent method in my application. It works fine when I hold down the [alt] key. The method only sends when the key is pressed, but not when I...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.