Mam mały problem z zapisem wysyłanego obrazka przez paperclipa do bazy danych. Obrazki ładnie się zapisują, jednak w momencie zapisu do bazy danych wartość dla pola image jest ustawiania na nil.
Siedzę już jakiś czas nad tym ale nadeszła pora poradzić się mądrzejszych głów, gdzie leży problem i jako go rozwiązać
[code]Model
class GalleryImage < ActiveRecord::Base
belongs_to :gallery_album
attr_accessible :description, :image, :title, :gallery_album_id
attr_accessor :image_file_name
has_attached_file :image, :styles => { :thumb => [“200x200#”, :png] },
:url => “/img/upl/:id_:style.:extension”,
:path => “:rails_root/public/img/upl/:id_:style.:extension”
validates_attachment_presence :image, :message => “Musi byc obrazek”
end
Migracja
class CreateGalleryImages < ActiveRecord::Migration
def change
create_table :gallery_images do |t|
t.string :title
t.text :description
t.string :image
t.references :gallery_album
t.timestamps
end
add_index :gallery_images, :gallery_album_id
end
end
Active Admin
ActiveAdmin.register GalleryImage do
form :html => { :encytpe => “multipart/form-data” } do |f|
f.inputs “Details” do
f.input :gallery_album_id, :as => :select, :collection => GalleryAlbum.all
f.input :title
f.input :description
f.input :image
end
f.buttons
end
end[/code]