Skip to content

Instantly share code, notes, and snippets.

@neotericdesign
Created November 16, 2010 15:19
Show Gist options
  • Select an option

  • Save neotericdesign/701921 to your computer and use it in GitHub Desktop.

Select an option

Save neotericdesign/701921 to your computer and use it in GitHub Desktop.
<%# add this field within the form: %>
<div class='field'>
<%= f.label :image -%>
<%= render :partial => "/shared/admin/image_picker", :locals => {
:f => f,
:field => :image_id,
:image => @engine.image, # obviously change the variable for your purposes
:toggle_image_display => false
} %>
</div>
<%# this should be all you have to do %>
# $: rails g migration AddImageIdToPages image_id:integer
# produces:
class AddImageIdToPages < ActiveRecord::Migration
def self.up
add_column :pages, :image_id, :integer
end
def self.down
remove_column :pages, :image_id
end
end
class Image < ActiveRecord::Base
#...
has_many :pages
#...
end
class Page < ActiveRecord::Base
#...
belongs_to :image
#...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment