If & else 语句更改 _form.html.erb 中的提交按钮文本 - Rails4

If & else statement to change submit button text in _form.html.erb - Rails4

谁能告诉我这是怎么写的:

文件: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。此外,而不是 if/else 使用三元运算符(oneliner):

f.button :submit, action_name == 'new' ? 'Post Job' : 'Update Job'

甚至更短:

<%= f.submit action_name == 'new' ? 'Post Job' : 'Update Job'%>