gpt4 book ai didi

ruby-on-rails - Rails - 如何在文本字段中执行 If 和 else 语句

转载 作者:太空宇宙 更新时间:2023-11-03 17:12:49 25 4
gpt4 key购买 nike

我正在尝试在此文本字段中使用以下值执行 if 和 else 语句:

<%= 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}" %>

我看到这个错误:

SyntaxError in Kategoris#show

Showing C:/Rails/konkurranceportalen/app/views/kategoris/_rating.html.erb where 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 => '...
... ^

最佳答案

我通常使用速记,像这样:

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

关于ruby-on-rails - Rails - 如何在文本字段中执行 If 和 else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5636484/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com