Philip Rhoades
2006-Jan-09 23:48 UTC
[Rails] Scaffolding - disabling Create, Edit, Destroy for some user logins?
People, I am using: before_filter :login_required in my Controllers and this works fine. For some tables I am happy to use the output of eg: ruby script/generate scaffold Author but is there some way that I can disable Create, Edit, Destroy for some user logins in the corresponding view? Thanks, Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney NSW 2001 Australia Mobile: +61:(0)411-185-652 Fax: +61:(0)2-8221-9599 E-mail: phil@pricom.com.au
Francois Beausoleil
2006-Jan-10 00:29 UTC
[Rails] Scaffolding - disabling Create, Edit, Destroy for some user logins?
Hello Philip ! 2006/1/9, Philip Rhoades <phil@pricom.com.au>:> but is there some way that I can disable Create, Edit, Destroy for some > user logins in the corresponding view?Yes, just use link_to_if instead of link_to in the views: <%= link_to_if current_user.login == ''admin'', ''Create'', :action => ''create'' %> Of course, any condition is possible. Hope that helps ! -- Fran?ois Beausoleil http://blog.teksol.info/
Philip Rhoades
2006-Jan-10 01:16 UTC
[Rails] Scaffolding - disabling Create, Edit, Destroy for some user logins?
Francois, On Mon, 2006-01-09 at 19:29 -0500, Francois Beausoleil wrote:> Hello Philip ! > > 2006/1/9, Philip Rhoades <phil@pricom.com.au>: > > but is there some way that I can disable Create, Edit, Destroy for some > > user logins in the corresponding view? > > Yes, just use link_to_if instead of link_to in the views: > > <%= link_to_if current_user.login == ''admin'', ''Create'', :action => ''create'' %> > > Of course, any condition is possible. > > Hope that helps !For this particular case I tried with: <%= link_to_if current_user.login == ''phil'', ''Edit'', :action => ''edit'' %>but I got an error: undefined local variable or method `current_user'' for #<#<Class:0xb7853e3c>:0xb7853d88> I installed the login_generator gem - does that make a difference? Thanks, Phil. -- Philip Rhoades Pricom Pty Limited (ACN 003 252 275 ABN 91 003 252 275) GPO Box 3411 Sydney NSW 2001 Australia Mobile: +61:(0)411-185-652 Fax: +61:(0)2-8221-9599 E-mail: phil@pricom.com.au
Kevin Olbrich
2006-Jan-10 01:19 UTC
[Rails] Re: Scaffolding - disabling Create, Edit, Destroy for some u
Francois Beausoleil wrote:> Hello Philip ! > > 2006/1/9, Philip Rhoades <phil@pricom.com.au>: >> but is there some way that I can disable Create, Edit, Destroy for some >> user logins in the corresponding view? > > Yes, just use link_to_if instead of link_to in the views: > > <%= link_to_if current_user.login == ''admin'', ''Create'', :action => > ''create'' %> > > Of course, any condition is possible. > > Hope that helps !That doesn''t disable the action, it just makes it inconvenient to use. The simple way to disable it for a given user would be to create another before filter. Have it check to see if the user has access to that action based on some criteria. If they don''t, redirect to a safe action. _Kevin -- Posted via http://www.ruby-forum.com/.