On Nov 10, 12:58 am, Scott Kulik <[EMAIL PROTECTED]>
wrote:
> Frederick Cheung wrote:

>
> thanks for the info fred.
>
> i was just thinking that I should probably do the checking to see if an
> item is locked in the model before updating.  so in item.rb:
>
Personally I would keep this in the controller. For example if you had
a cron job that updating items at night or something like that you
wouldn't want to have to fake up a user for that.

Fred

>   before_save :validate
>
>   def validate
>
>     @user = User.find_by_id(session[:user_id])
>
>     if self.locked == 1 && @user.admin == 1
>       self.errors.add_to_base("This item is locked and can only be
> edited by an administrator.")
>       return false
>     end
>   end
>
> the only problem i have here is that I am unable to access the session
> variable or the "admin?" function in my authenticated_system library.
>
> is there an easy solution to check if a user is an admin from a model?
> this way sounds like it might be a little easier then using a
> boilerplate.
> --
> Posted viahttp://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to