Hello,
I’m just starting out with both Rails and Ruby, so I hope this isn’t too
simple of a question - but I’ve been struggling to find a solution.
I’m using the file_column plugin to handle image uploads and thumbnail
generation. In addition, I’ve wrapped the image into a polymorphic
table
so I can have uploaded images associated with multiple datatypes.
However, I’m having trouble determining how to reference the file_column
field in the images table from an associated view.
As an example, here’s a condensed version of the relationships:
create_table :images do |t|
t.column :file, :string
t.column :illustrated_id, :integer
t.column :illustrated_type, :string
end
create_table :thing do |table|
table.column :name, :string
table.column :description, :string
end
…and models:
class Thing < ActiveRecord::Base
has_one :image, :as => :illustrated
end
class Image < ActiveRecord::Base
belongs_to :illustrated, :polymorphic => true
file_column :file, :magick => {
:versions => { “thumb” => “100x100”, “medium” => “640x480>” },
:attributes => { :format => “JPG” }
}
end
Now, in an Image view - which in practice I don’t think I would use, but
for the sake of demonstration - I can do something like this to get the
uploads working without a problem:
<%= file_column_field “image”, “file” %>
But how would I do the same from the so-called “Thing” view? Or is it
not
possible to handle in the view without writing a model method? I’d
prefer
not to, as there would be several models with duplicated code.
Thank you!
Dan Naab