[英]How to replace "Update" button by "Save" and "Cancel" buttons in a Ruby on Rails application with "form_with" form helper?
I am using a form in a rails application in order to update a record.我在 Rails 应用程序中使用表单来更新记录。
<%= form_with model: @article do |form| %>
<%= form.text_field :title %>
<%= form.text_area :body %>
<%= form.submit %>
<% end %>
But I don't want only one "Update" button, I would like 2 buttons (Save and Cancel).但我不想要一个“更新”按钮,我想要两个按钮(保存和取消)。 How can I do that?
我怎样才能做到这一点?
For a Cancel button, you could use a link_to
to redirect to a different page.对于取消按钮,您可以使用
link_to
重定向到不同的页面。
<%= link_to 'Cancel', preferred_redirect_path %>
To change the text for the submit
you can use the following.要更改
submit
的文本,您可以使用以下内容。
<%= f.submit "Custom Text" %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.