Skip to content

Instantly share code, notes, and snippets.

@andrellima
Created March 24, 2011 12:03
Show Gist options
  • Save andrellima/884944 to your computer and use it in GitHub Desktop.
Save andrellima/884944 to your computer and use it in GitHub Desktop.
_form.html.erb
<%= form_for(@gallery) do |f| %>
<% if @gallery.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@gallery.errors.count, "error") %> prohibited this gallery from being saved:</h2>
<ul>
<% @gallery.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<% f.fields_for :gallery_photos do |gf_form| %>
<%= gf_form.label :photo, 'Photo:' %>
<%= gf_form.file_field :photo %>
<% end %>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
class Gallery < ActiveRecord::Base
has_many :gallery_photos
accepts_nested_attributes_for :gallery_photos
end
class GalleryPhoto < ActiveRecord::Base
belongs_to :gallery
has_attached_file :photo, :styles => { :medium => "300x300>", :thumb => "100x100>" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment