submit button label ?

15 views
Skip to first unread message

PC Leung

unread,
May 14, 2014, 2:56:47 AM5/14/14
to hk...@googlegroups.com
in ../app/views/products/_form.html.erb

there are few lines

  <div class="actions">
     <%= f.submit %>
  </div>

after clicking a new_product_path, it goes to new.html.erb

<%= render 'form' %>
<%= link_to 'Back', products_path %>

How come the form shows "Create Products" in the submit button?

where is the "Create Products" coming from?

thanks

3dd13

unread,
May 14, 2014, 3:13:03 AM5/14/14
to hk...@googlegroups.com
it depends on the @product object you provided to
  <%= form_for(@product, ...

if the @product is still a new record, the form builder is smart enough to say "Create Product",
if the @product is an existing record, it will say "Update Product" 

you can refer to Rails doc, or check their source code:
  http://apidock.com/rails/ActionView/Helpers/FormBuilder/submit







--
You received this message because you are subscribed to the Google Groups "Hong Kong Ruby on Rails" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hkror+un...@googlegroups.com.
To post to this group, send email to hk...@googlegroups.com.
Visit this group at http://groups.google.com/group/hkror.
For more options, visit https://groups.google.com/d/optout.

Matthew Rudy Jacobs

unread,
May 14, 2014, 5:03:45 AM5/14/14
to hk...@googlegroups.com

I believe if you say f.submit "save" it will use that as the button text.

Graham Milosevic

unread,
May 14, 2014, 8:13:12 AM5/14/14
to hk...@googlegroups.com

You can also control there text using your locale yaml files. Which is normally my approach since having to use multiple languages.

You can change any of the labels for models using an existing path set by rails.

http://guides.rubyonrails.org/i18n.html#translations-for-active-record-models

Reply all
Reply to author
Forward
0 new messages