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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -