有人可以告诉我这是如何写得正确的:
file: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 %>
答案 0 :(得分:2)
您想使用action_name
。另外,代替if/else
使用三元运算符(oneliner):
f.button :submit, action_name == 'new' ? 'Post Job' : 'Update Job'
甚至更短:
<%= f.submit action_name == 'new' ? 'Post Job' : 'Update Job'%>