generate a form based on object
Is there any available plugin or gem which can generate a form based on some object tha开发者_运维知识库t could be a hash or hash from yml.
Basically, wanted to create an app to mange other application configurations where I am going to read existing app-config files and create some form based on it to update from UI.
Suggests if there is an existing way to do it.
With formtastic you can do:
<% semantic_form_for @object do |f| %>
<%= f.inputs %>
<%= f.buttons %>
<% end %>
And it will make form fields for every db column automatically.
For a plain hash object this might get you part of the way there:
config = { :host => 'localhost', :port => '3000', :path => 'foo/bar' }
<% form_tag set_config_path %>
<% config.each do |key, value| %>
<input type='text' name='<%= key %>' value='<%= value %>'/>
<% end %>
<%= submit_tag 'save' %>
<% end %>
You may need to namespace the key names to fit the params key you want.
edit: Whoa, whoa. This Gem just came out today. Almost as if just for you:
https://github.com/joshsusser/informal
精彩评论