请告诉我如何正确编写:
文件:views/adverts/_form.html.erb
<% if action: "new" %>
<div class="form-actions">
<%= f.button :submit, 'Post Job' %>
</div>
<% else %>
<div class="form-actions">
<%= f.button :submit, 'Update Job' %>
</div>
<% end %>
最佳答案
您想使用action_name
。另外,使用三元运算符(oneliner)代替 if/else
:
f.button :submit, action_name == 'new' ? 'Post Job' : 'Update Job'
或更短:
<%= f.submit action_name == 'new' ? 'Post Job' : 'Update Job'%>
关于ruby-on-rails - if & else 语句更改 _form.html.erb 中的提交按钮文本 - Rails4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34927181/