开发者

generate a form based on object

开发者 https://www.devze.com 2023-02-24 08:00 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号