Walter Lee Davis
unread,Apr 13, 2014, 1:19:31 PM4/13/14Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
Inside the form_for helper, f.submit will create a different button based on the state of the object the form is based upon. So you get Create Widget or Update Widget, depending on whether the @widget is persisted already or not. Very nice.
Now what if my @widget was actually a reserved word, and I had masked this in my application by creating a set of routes for the reserved word that pointed to the actual controller. This works, for example:
resources :actions, controller: :fw_actions
resources :fw_actions
The resulting Save/Update button looks awful, though, (Create Fw action) and I can't find any good way to override it without manually testing if the @fw_action is persisted or not. Is there a central place in Rails 4.0.4 to override the naming conventions used within these helpers? I've read through the API documentation and the Rails Guides without finding any parameter I can set to do this.
This works:
<%= f.submit (f.object.persisted? ? 'Update Action' : 'Create Action') %>
...but it's ugly. This issue also means religiously applying the path helpers everywhere to make the URL stay coherent, rather than being able to just redirect_to @fw_action from the controller, or link_to @fw_action in the view. I can recall using the i18n framework to change the labels on fields, but as far as I can tell, that doesn't allow you to change the visible name of the model itself. Is there another way?
Thanks in advance,
Walter