Reputation: 77
I have one check_box in form:
<%= f.check_box :user, {checked: true if current_user.id == "1"} %>
and here I'm getting syntax error, while here:
<%= f.check_box :user, {checked: if current_user.id == "1"
true
end} %>
everything works fine. What am I missing?
Upvotes: 1
Views: 62
Reputation: 1951
You need to clarify the sentence:
<%= f.check_box :user, {checked: (true if current_user.id == "1")} %>
# or maybe...
<%= f.check_box :user, {checked: true if (current_user.id == "1")} %>
Btw, you don't need the if
, just the result of the condition. Try:
<%= f.check_box :user, {checked: (current_user.id == 1)} %>
Upvotes: 4