-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamical attr_accessible attributes #18
Comments
You can certainly do this and assign the name_translations hash directly. Does it work for your use case? |
Do you have an example?
|
robworley: my problem is the attr_accessible part. at the moment i have to add :name_en, :name_fr, etc. Is there another way to have this dynamic for several locales? |
Sorry for the late response. Here's one way to do it: class Product < ActiveRecord::Base
I18n.available_locales.each { |locale| attr_accessible "name_#{locale}" }
translates :name
end Then in the view template: <%= form_for @product do |f| %>
<% I18n.available_locales.each do |locale| %>
<%= f.label "name_#{locale}" %>
<%= f.text_field "name_#{locale}" %>
<% end %>
<%= submit_tag %>
<% end %> |
Is there a nice way to do this in Rails 4? I understand I have to list all fields as strong params, but I've been unable to find any nice looking solution if there are many locales and a lot of translated fields. |
Instead of defining each several language for attr_accessible
it would be nice to set only one central attribute.
Is there a way to change this behavior?
The text was updated successfully, but these errors were encountered: