Answer the question
In order to leave comments, you need to log in
Ruby on Rails 3 - iterator for model accessors?
The question is in the context of Ruby on Rails 3.0.3.
Given: a model (it is also an entity, it is also a table) with 30+ fields (they are attributes, accessors). there is a scaffolding view ( link to the source ), in which the name and value of the field is displayed in plain text. The trouble is that here the field names are hard-coded in the view. I would like these to be variables, since the localization module is connected.
Required: not to write down all 30+ fields in HTML in plain text, but to go through all the attributes of the model and take its own i18n-name (Lastname or Surname) for each attribute. Well, bring it out.
@request.to_a.each doesn't help, since lastname type attributes are like accessors, that is, methods (?).
Maybe I'm missing something somewhere, please explain.
https://gist.github.com/713493
Answer the question
In order to leave comments, you need to log in
Happened:
<% @request.attributes.each do |a,b| %>
<p>
<strong><%=t "activerecord.attributes.request.#{a}" %>:</strong>
<em><%=h b %></em></p>
<% end %>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question