Forum: Ruby on Rails attachment_fu thumbnails

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
schaf88 (Guest)
on 2007-04-21 19:32
howdy!
I had the problem that attachment_fu didn't make a thumbnail, but
everything else worked. I read this post
http://www.ruby-forum.com/topic/104213 and added a parent_id column. now
I get the following error when I trie to add a photo:

undefined method `find_or_initialize_by_thumbnail_and_parent_id' for
Photo:Class

my code is:

class Photo < ActiveRecord::Base
  has_attachment :content_type => :image,
                 :storage => :file_system,
           :max_size => 1.megabyte,
                 :thumbnails => { :thumb => '164x164>' }
end

create_table :photos do |t|
  t.column :filename, :string
  t.column :posted_on, :datetime
  t.column :description, :text
  t.column :name, :string
end

def create
  @photo = Photo.new(params[:photo])
  if @photo.save
    redirect_to :action => 'list'
  else
    render :action => 'new'
  end
end
Rick O. (Guest)
on 2007-04-21 22:35
(Received via mailing list)
> undefined method `find_or_initialize_by_thumbnail_and_parent_id' for

The plugin is written for rails 1.2.  I have an old tagged
acts_as_attachment plugin for 1.1.6:
http://svn.techno-weenie.net/projects/plugins/tags...

--
Rick O.
http://lighthouseapp.com
http://weblog.techno-weenie.net
http://mephistoblog.com
schaf88 (Guest)
on 2007-04-23 16:23
thanks, but i'm using rails 1.2.2
Vineeth P. (Guest)
on 2011-04-07 14:01
schaf88 wrote in post #236924:
> howdy!
> I had the problem that attachment_fu didn't make a thumbnail, but
> everything else worked. I read this post
> http://www.ruby-forum.com/topic/104213 and added a parent_id column. now
> I get the following error when I trie to add a photo:
>
> undefined method `find_or_initialize_by_thumbnail_and_parent_id' for
> Photo:Class
>
> my code is:
>
> class Photo < ActiveRecord::Base
>   has_attachment :content_type => :image,
>                  :storage => :file_system,
>            :max_size => 1.megabyte,
>                  :thumbnails => { :thumb => '164x164>' }
> end
>
> create_table :photos do |t|
>   t.column :filename, :string
>   t.column :posted_on, :datetime
>   t.column :description, :text
>   t.column :name, :string
> end
>
> def create
>   @photo = Photo.new(params[:photo])
>   if @photo.save
>     redirect_to :action => 'list'
>   else
>     render :action => 'new'
>   end
> end

My first guess, You don't have 'thumbnail' column in your database
table.
The clue is in the error message:
'find_or_initialize_by_thumbnail_and_parent_id', means attachment_fu
looks for both 'thumbnail' and 'parent_id' column

My db table looks something like this and it works fine.
create_table :photos do |t|
      t.string   :filename,     :null => false
      t.string   :content_type
      t.string   :thumbnail
      t.integer  :size
      t.integer  :width
      t.integer  :height
      t.integer  :parent_id
      t.integer  :album_id
This topic is locked and can not be replied to.