Skip to content

Instantly share code, notes, and snippets.

@vinniefranco
Created January 28, 2011 00:16
Show Gist options
  • Save vinniefranco/799580 to your computer and use it in GitHub Desktop.
Save vinniefranco/799580 to your computer and use it in GitHub Desktop.
= form_for @gallery, :html => { :multipart => true }, :remote => true do |f|
%ol.dialog.form
%li.text
= f.label :title
= f.text_field :title
%li.select
= f.label :parent_id, 'Parent'
= f.select :parent_id , @galleries.collect {|g| [g.title, g.id]}, { :include_blank => 'Pick a parent' }
%li.file
- f.fields_for :image do |image|
= image.label :asset, 'Thumbnail'
= image.file_field :asset
%li.submit
= f.submit
#form_wait
class PhotoGalleriesController < ApplicationController
respond_to :html, :json, :js
...
def new
@galleries = PhotoGallery.current_clients_galleries(current_client.id)
@gallery = PhotoGallery.new
@gallery.build_image
@form = render_to_string :partial => 'form'
respond_with(@gallery)
end
class PhotoGallery < ActiveRecord::Base
# Poster image for gallery
has_one :image,
:conditions => { :table_name => :galleries },
:foreign_key => "table_id"
accepts_nested_attributes_for :image, :reject_if => proc { |attributes| attributes['asset'].blank? }
...
class Image < ActiveRecord::Base
...
belongs_to :photo_gallery, :foreign_key => 'table_id', :inverse_of => :image
has_attached_file :asset,
:storage => :s3,
:s3_credentials => "#{RAILS_ROOT}/config/s3.yml",
:path => "/media/:class/:attachment/:style.:filename",
:bucket => '******'
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment