Skip to content

Instantly share code, notes, and snippets.

@mhenrixon
Created May 9, 2011 17:35
Show Gist options
  • Save mhenrixon/962939 to your computer and use it in GitHub Desktop.
Save mhenrixon/962939 to your computer and use it in GitHub Desktop.
Strange carrierwave insert
class Dog < ActiveRecord::Base
attr_accessible :name, :pictures_attributes
has_many :pictures, as: :attachable
accepts_nested_attributes_for :pictures
end
=f.semantic_fields_for :pictures do |pic|
=pic.inputs do
=pic.hidden_field :id
=pic.hidden_field :attachable_id
=pic.hidden_field :attachable_type
=pic.file_field :image
INSERT INTO "pictures" ("created_at", "updated_at", "image", "attachable_id", "attachable_type") VALUES (
'2011-05-09 16:38:56.676612',
'2011-05-09 16:38:56.676612',
'--- !ruby/object:ActionDispatch::Http::UploadedFile
content_type: image/jpeg
headers: |
Content-Disposition: form-data; name="dog[pictures_attributes][0][image]"; filename="IMG_0450.JPG"
Content-Type: image/jpeg
original_filename: IMG_0450.JPG
tempfile: !ruby/object:File {}',
1,
'Dog')
class Picture < ActiveRecord::Base
belongs_to :attachable, polymorphic: true
belongs_to :dog, through: :attachable
attr_accessible :image, :attachable_id, :attachable_type
mount_uploader :image, ImageUploader
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment