I'm a beginner.
If you want to display the results in view from the results obtained from the model,
If the contents of the model become variable (the process of changing the model with connection each time)
Some get the table @a aa, while others get the table b.
In the case of this book, the result is 1 view per controller, so there are many descriptions that specify the result of the line and output it.
<%@ado|a|%>
<tr>
<td><%=a.id%>/td>
<td><%=a.title%></td>
</tr>
<%end%>
</table>
How do I get this dynamically because the table that pulls it is different as above, so if I specify a column name, it will not be reflected in the view?
Or if there is a website that you can refer to, I would appreciate it if you could let me know.
ruby-on-rails ruby rails-activerecord
You can use the class method columns
to obtain column names, etc. (a.class.columns
).
<%@a.each do|a|%>
<%a.class.columns.map(&:name).each do|n|%>
<%=a.send(n)%>
<%end%>
<%end%>
Other Possible Methods:
a.try(:title)
)
© 2024 OneMinuteCode. All rights reserved.