2009/3/11 Carlos Santana <[email protected]>

>
> Thanks Colin..
>
> I am using ternary operator on @currentuser:
> @currentuser ? can_admin?(topic) : false .
>
> User model method: topic_admin changed to can_create
> Topic model method: can_admin changed to can_be_created_by
>
> @currentuser.can_create?(topic)
>
> ### User model has this method:
> def can_create?(topic)
>  topic.can_be_created_by?(self)
> end
> ----
>
> ### Topic model has this method:
> def can_be_created_by?(user)
>   valid_roles = %w{admin editor}
>  if valid_roles.include?(user.role.name)
>    return true
>  else
>    return false
>  end
> end
> ---
>
> Problem -
> I have nested resources in my application - (topic has_many items). And
> on my show topic page I have a link to 'Add new item'. I would like to
> show this link only to users with certain roles. However, I am not able
> to pass this resource (item) as it has not been initialized. So how can
> I call method like: @currentuser.can_create?(item) from my show topic
> page. I am initializing resource objects within the controller, but how
> can I initialize these from my view? Do I need to? Any clues?
>
>
Are there different types of Topic? If not then can_create? does not need to
be given a topic.  Make can_be_created_by? a class method rather than an
instance method, so it is called by Topic.can_be_created_by?(user).

Colin

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