Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In my Rails 3.2.13 app the attribute labels are picked up automatically from the model whose attributes are embedded. Please note that I am nesting attributes of the belongs_to model, but it might also work the other way around. </p> <p>My example from working code:</p> <p>The models:</p> <pre><code>class User &lt; ActiveRecord::Base belongs_to :account accepts_nested_attributes_for :account # ... end class Account &lt; ActiveRecord::Base has_many :users end </code></pre> <p>The view:</p> <pre><code>&lt;h2&gt;&lt;%= t(:sign_up) %&gt;&lt;/h2&gt; &lt;%= form_for(resource, :as =&gt; resource_name, :url =&gt; registration_path(resource_name)) do |f| %&gt; &lt;%= devise_error_messages! %&gt; &lt;div&gt;&lt;%= f.label :email %&gt;&lt;br /&gt; &lt;%= f.email_field :email %&gt;&lt;/div&gt; &lt;%= f.fields_for :account do |account_form| %&gt; &lt;div&gt;&lt;%= account_form.label :subdomain %&gt;&lt;br /&gt; &lt;%= account_form.text_field :subdomain %&gt;.&lt;%= request.host %&gt; &lt;span class="hint"&gt;&lt;/span&gt;&lt;/div&gt; &lt;% end %&gt; </code></pre> <p>translations_de.yml:</p> <pre><code>activerecord: models: account: Konto user: Benutzer attributes: account: name: Firmenname subdomain: Subdomain users: Benutzer user: # ... no sign of subdomain here ... </code></pre> <p>And the view is rendered with the subdomain label translated based on </p> <pre><code>activerecord.attributes.account.subdomain </code></pre> <p>Nice. :)</p> <p>I'm not sure but it might require you to use the activerecord path instead of the helpers one.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload