On 25 Nov 2011 07:58, "Mauro" wrote:
What's the difference between:
@current_role = current_user.try(:role) || :guest
@current_role = current_user.try(:role) || "guest"
One sets @current_role as a string, the other as a symbol...
Are you asking "what's the difference between strings and symbols?" - if
so, Google is your friend.
As an aside, it may be cleaner code to not store the value in a new
instance variable in your controller, but to have a method called
current_role on the User model that does the same calculation. It'll end up
DRYer this way.
(Actually, if it were me, i would probably put a default value if 'guest'
in the db field for current_user.role and validate the potential values to
a list ...)
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 firstname.lastname@example.org.
To unsubscribe from this group, send email to email@example.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.