Created
July 28, 2010 07:51
-
-
Save basti/493710 to your computer and use it in GitHub Desktop.
Code to generate model related views and YML files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
# 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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# generate YML model attribute translation file | |
model = YourModel | |
model.column_names.each do |col| | |
puts "#{col}: #{col.humanize}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% | |
# 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