Forum: Ruby on Rails Customizing the automatic Submit button

A47e0a6beeb9d048ff054fc1c3a97418?d=identicon&s=25 Walter Davis (walterdavis)
on 2014-04-13 19:21
(Received via mailing list)
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,

6883e5ef03484d4fcef507d7b4f1d243?d=identicon&s=25 Matt Jones (Guest)
on 2014-04-15 21:46
(Received via mailing list)
On Sunday, 13 April 2014 13:19:31 UTC-4, Walter Lee Davis 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 Jones
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.