simple form - rails submit_tags to different actions -
<%= simple_form_for@equipment, :url => equipments_path, :method => :post |f| %> .... <% if @equipment.id.present? %> <div class="actions"> //todo submit_tag action update </div> <% else %> <div class="actions"> <%= submit_tag "adicionar equipamento" %> </div> <% end %> <% end %>
in example have 2 buttons,if object exists have first button , when not exists have second button. second button send request controller equipments#create. how can send request equipments#update in first button ?
<%= simple_form_for @equipment |f| %> <div class="actions"> <%= submit_tag(@equipment.persisted? ? "create equipment" : "update equipment") %> </div> <% end %>
this short way it.
usually use i18n translate these labels. (see: i18n model-specific rails submit button)
Comments
Post a Comment