goldie
goldie

Reputation: 77

Reason for syntax error in conditional statement

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

Answers (1)

CAmador
CAmador

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

Related Questions