Customizing the automatic Submit button

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,


On Sunday, 13 April 2014 13:19:31 UTC-4, Walter Lee D. wrote:

    resources :actions, controller: :fw_actions

I haven’t dug too deep on it, but maybe overriding some of the methods
ActiveModel::Naming (class methods in your FwAction model) would do what
you’re looking for?

–Matt J.