On Sunday, 13 April 2014 13:19:31 UTC-4, Walter Lee Davis wrote:
>
> 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? 
>
>
I haven't dug too deep on it, but maybe overriding some of the methods from 
ActiveModel::Naming (class methods in your FwAction model) would do what 
you're looking for?

http://api.rubyonrails.org/classes/ActiveModel/Naming.html

--Matt Jones 

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/e499fbaa-da37-419d-b9f0-ca868c9fbb0a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to