Scaffolding - disabling Create, Edit, Destroy for some user

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 R.

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: [email protected]

Hello Philip !

2006/1/9, Philip R. [email protected]:

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 !

Francois,

On Mon, 2006-01-09 at 19:29 -0500, Francois B. wrote:

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 R.

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: [email protected]

Francois B. wrote:

Hello Philip !

2006/1/9, Philip R. [email protected]:

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs