Tuesday 15 July 2014

ruby on rails - How do I get this if statement with && to work properly? -



ruby on rails - How do I get this if statement with && to work properly? -

i have in view:

<% if user_signed_in? && current_user.has_role? :admin or :editor %>

this returns error:

syntax error, unexpected tsymbeg, expecting keyword_then or ';' or '\n'

i tried this:

<% if user_signed_in? , current_user.has_role? :admin or :editor %>

and while don't above error, doesn't work @ all...i.e. non-signed-in-user can access content within if block.

i don't think has_role? can take more 1 parameter. right way is:

<% if user_signed_in? && (current_user.has_role? :admin or current_user.has_role? :editor) %>

ruby-on-rails ruby ruby-on-rails-4 devise cancancan

No comments:

Post a Comment