ruby - Rails - How to do If and else statements in a text field -


i trying if , else statement in text field value:

<%= f.text_field :rating, :size => 1, :min => 1, :max => 6, :value => if vind.ratings == 0 else vind.rating_score/vind.ratings, :type => 'range', :step => '1', :id => "#{vind.id}" %> 

i error in view:

syntaxerror in kategoris#show  showing c:/rails/konkurranceportalen/app/views/kategoris/_rating.html.erb line #3 raised:  c:/rails/konkurranceportalen/app/views/kategoris/_rating.html.erb:3: syntax error, unexpected keyword_else, expecting keyword_then or ';' or '\n' ...ue => if vind.ratings == 0 else vind.rating_score/vind.ratin... ...                               ^ c:/rails/konkurranceportalen/app/views/kategoris/_rating.html.erb:3: syntax error, unexpected ',', expecting ')' ...vind.rating_score/vind.ratings, :type => 'range', :step => '... ...                               ^ 

i use shorthand, this:

:value => ( vind.ratings == 0 ? 0 : vind.rating_score/vind.ratings ) 

Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -