Skip to content

Instantly share code, notes, and snippets.

@pullmonkey
Created November 16, 2011 20:59
Show Gist options
  • Save pullmonkey/1371372 to your computer and use it in GitHub Desktop.
Save pullmonkey/1371372 to your computer and use it in GitHub Desktop.
formgen sample form
<%= form_for setup_foo(@foo), :html => { :multipart => true } do |f| %>
<% if @foo.errors.any? %>
<div id="errorExplanation">
<h2><%= pluralize(@foo.errors.count, "error") %> prohibited this foo from being saved:</h2>
<ul>
<% @foo.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :description %>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :image %>
<%= f.file_field :image %>
</div>
<div class="field">
<%= f.label :other_ids, "Others" %>
<%= f.select :other_ids, build_select_list(:others), {:prompt => "Please select"}, {:multiple => true, :size => 4} %>
</div>
<div class="field">
<%= f.label :something_id, "Something" %>
<%= f.select :something_id, build_select_list(:something), {:prompt => "Please select one"} %>
</div>
<%= f.fields_for :baz do |nf| %>
<%= render 'baz_fields', :f => nf %>
<% end %>
<%= f.fields_for :bars do |nf| %>
<%= render 'bar_fields', :f => nf %>
<% end %>
<%= link_to_add_fields "Add bar", f, :bars %>
<%= f.submit "Save" %>
<% end %>
<%= content_for :head do %>
<%= javascript_include_tag 'jquery.add_remove_links.js' %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment