Skip to content

Instantly share code, notes, and snippets.

@basti
Created July 28, 2010 07:51
Show Gist options
  • Save basti/493710 to your computer and use it in GitHub Desktop.
Save basti/493710 to your computer and use it in GitHub Desktop.
Code to generate model related views and YML files
<%
# generate RHTML/erb code for displaying all model columns
model = YourModel
%>
<ul>
<% model.column_names.each do |col| %>
<li>
< %= <%= model.model_name %>.human_attribute_name("<%= col %>").humanize %>:
< %= @<%= model.model_name.downcase %>.<%= col %> %>
</li>
<% end %>
</ul>
# generate YML model attribute translation file
model = YourModel
model.column_names.each do |col|
puts "#{col}: #{col.humanize}"
end
<%
# generate RHTML/erb code for model form (presumes all attributes are text, i.e. in text field)
model = YourModel
%>
<% model.column_names.each do |col| %>
<div class="field">
< %= f.label :<%= col %> %><br />
< %= f.text_field :<%= col %> %>
</div>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment