Rails: How to change the text on the submit button in a Rails Form

后端 未结 10 885
你的背包
你的背包 2020-12-07 15:19

i have listed my _form.html.erb file below what i would like to do is change the text on the submit button i know how to do it in html but not shure how to do it in Rails 3<

相关标签:
10条回答
  • 2020-12-07 15:43

    When writing in erb

    <%= f.submit "your text" %>

    when writing in HAML

    = f.button :submit, "your text"
    

    In HAML comma should be there after submit otherwise it will throw error.

    0 讨论(0)
  • 2020-12-07 15:46

    Sometimes using helpers is not acceptable because of used text or you need additionally add class etc., so you can directly override value:

    <%= f.submit class: 'btn btn-primary', value: 'Login' %>
    

    or:

    <%= f.button :submit, class: 'btn btn-primary', value: 'Login' %>
    

    By the way it was mentioned by @cassi.lup in comment to accepted answer.

    Tested on Rails 4.2.3.

    0 讨论(0)
  • 2020-12-07 15:48

    for Slim version use value="xyz" to change the default submit input text.

    0 讨论(0)
  • 2020-12-07 15:51

    Its simple, use

    <%= f.submit 'Desired text on the button' %>
    
    0 讨论(0)
  • 2020-12-07 16:01

    If you want to change all create and update form submit tags, this change is easy to make. Modify config/locales/en.yml like so:

    en:
      helpers:
        submit:
          create: "Crear un %{model}"
          update: "Confirmar cambios al %{model} creado"
    
    0 讨论(0)
  • 2020-12-07 16:02

    Building on @daniel's answer, you can also customize submit tag values on a per-model basis:

    en:
      helpers:
        submit:
          model_name:
            create: "Create"
            update: "Update"
    

    And then in your form you can just use:

    <%= f.submit %>
    

    See here for the documentation (second example.)

    0 讨论(0)
提交回复
热议问题