# Scaffolding - disabling Create, Edit, Destroy for some user

**URL:** <https://www.ruby-forum.com/t/scaffolding-disabling-create-edit-destroy-for-some-user/60654>\
**Category:** Rails\
**Created:** [January 10, 2006, 12:50am UTC](https://www.ruby-forum.com/t/scaffolding-disabling-create-edit-destroy-for-some-user/60654 "2006-01-10T00:50:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [January 10, 2006, 12:50am UTC](https://www.ruby-forum.com/t/scaffolding-disabling-create-edit-destroy-for-some-user/60654/1 "2006-01-10T00:50:22Z")

</div>

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: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [January 10, 2006, 1:32am UTC](https://www.ruby-forum.com/t/scaffolding-disabling-create-edit-destroy-for-some-user/60654/2 "2006-01-10T01:32:36Z")

</div>

Hello Philip !

2006/1/9, Philip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> 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 !

---

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [January 10, 2006, 2:17am UTC](https://www.ruby-forum.com/t/scaffolding-disabling-create-edit-destroy-for-some-user/60654/3 "2006-01-10T02:17:49Z")

</div>

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: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![unebaguettesvp](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/u/47e85d/32.png) [@unebaguettesvp](https://www.ruby-forum.com/u/unebaguettesvp)\
**Post date:** [January 10, 2006, 2:19am UTC](https://www.ruby-forum.com/t/scaffolding-disabling-create-edit-destroy-for-some-user/60654/4 "2006-01-10T02:19:47Z")

</div>

Francois B. wrote:

> Hello Philip !
> 
> 2006/1/9, Philip R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > 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
