Problem with acts_as_attachment plugin

I thought I’d give the acts_as_attachment plugin a try. So I follow
the tutorial on this page:

http://weblog.techno-weenie.net/articles/acts_as_attachment

and it looks like everything installed fine. So I fired up Webrick and
tried to upload an image (I changed it from dvd_covers to book_covers,
but otherwise no changes.)

When I select my image on the New page, and click create I get an error:

ActiveRecord::RecordNotFound in Book coversController#show

Couldn’t find BookCover with ID=0

Request

Parameters: {“id”=>“0”}

An item is added to the database with id=1, and the file is “uploaded”
to the public/book_covers/ directory. If I then try to look at the
file by going to /localhost/book_covers/ and clicking on the item
that’s listed, I get a missing image and another error in the log:

Session ID: 345f86366e41bc32e5883f3fbffa1efd
Parameters: {“action”=>“show”, “id”=>“0”, “controller”=>“book_covers”}
BookCover Load (0.000822) SELECT * FROM book_covers WHERE
(book_covers.id = ‘0’) LIMIT 1

ActiveRecord::RecordNotFound (Couldn’t find BookCover with ID=0):

I don’t know why it’s looking for id = 0, the link in the index page is:

  • 06.jpg
  • and on the show page:

    06

    Did I miss something?

    Thanks,

    John

    On 9/8/06, John T. [email protected] wrote:

    file by going to /localhost/book_covers/ and clicking on the item
    I don’t know why it’s looking for id = 0, the link in the index page is:
    John

    Just a quick followup - the image is uploaded, but the path it’s
    uploaded to is:

    public/book_covers/0/test.jpg

    I don’t know why it’s showing 0. The database clearly shows id = 1:

    sqlite> select * from book_covers;
    1|image/jpeg|06.jpg|65559||||

    Help!

    Thanks

    On 9/8/06, John T. [email protected] wrote:

    Just a quick followup - the image is uploaded, but the path it’s uploaded to is:

    public/book_covers/0/test.jpg

    I don’t know why it’s showing 0. The database clearly shows id = 1:

    sqlite> select * from book_covers;
    1|image/jpeg|06.jpg|65559||||

    A further followup… for some reason, statements in the create method:

    @book_cover = DvdCover.create! params[:book_cover]
    redirect_to :action => ‘show’, :id => @book_cover

    are setting the :id to 0, and then all heck breaks loose.

    Anyone… anyone?

    jt

    On 9/8/06, John T. [email protected] wrote:

    Here’s yet more info. Clearing everything out and clicking on New,
    then selecting an image and clicking submit and I get this in the log:

    Processing BookCoversController#create (for 127.0.0.1 at 2006-09-08
    20:20:50) [POST]
    Session ID: 345f86366e41bc32e5883f3fbffa1efd
    Parameters: {“commit”=>“Create”, “action”=>“create”,
    “book_cover”=>{“uploaded_data”=>#<File:/tmp/CGI833.0>},
    “controller”=>“book_covers”}
    SQL (0.006686) PRAGMA table_info(book_covers)
    Exception working with image: undefined method `columns’ for
    #String:0x22ae4ac
    SQL (0.001709) INSERT INTO book_covers (“content_type”, “size”,
    “thumbnail”, “filename”, “height”, “parent_id”, “width”)
    VALUES(‘image/jpeg’, 65559, NULL, ‘06.jpg’, NULL, NULL, NULL)
    @book_cover.id = 0
    Redirected to http://localhost:3000/book_covers/show/0
    Completed in 0.52382 (1 reqs/sec) | DB: 0.00839 (1%) | 302 Found
    [http://localhost/book_covers/create]

    Please!!

    On 9/8/06, John T. [email protected] wrote:

    A further followup… for some reason, statements in the create method:

    @book_cover = DvdCover.create! params[:book_cover]
    redirect_to :action => ‘show’, :id => @book_cover

    Obviously, the code is actually:

    @book_cover = BookCover.create! params[:book_cover]
    redirect_to :action => ‘show’, :id => @book_cover

    With the same result - id is 0, folder created is 0, id of record in
    database is 1.

    Ok.

    So I tried to run the test for the plug in and I get this:

    ~/RoR/test john$ rake test_plugins
    (in /Users/john/RoR/test)
    /usr/local/bin/ruby -Ilib:test
    “/usr/local/lib/ruby/gems/1.8/gems/rake-0.7.1/lib/rake/rake_test_loader.rb”
    “vendor/plugins/acts_as_attachment-1.1.6/test/attachment_test.rb”
    – create_table(:attachments, {:force=>true})
    /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
    `gem_original_require’: no such file to load – sqlite
    (MissingSourceFile)

    Looks like it’s trying to create a sqlite (vs sqlite3) db? The db I’m
    using is sqlite3 so I don’t know why it’s it’s trying to use sqlite.

    Help!

    On 9/8/06, John T. [email protected] wrote:

    Ok.

    So I tried to run the test for the plug in and I get this:

    (Is anyone even seeing these??)

    I got the tests to run by editing the database.yml file within the
    test folder of the plugin to only use sqlite3 (I’d figure it would
    pick the right database - guess not…)

    But that doesn’t help. That generated:

    47 tests, 35 assertions, 0 failures, 39 errors
    rake aborted!
    Command failed with status (1): [/usr/local/bin/ruby -Ilib:test
    "/usr/local…]

    Here’s the results of the first test:

    1. Error:
      test_filesystem_size_for_file_attachment(AttachmentTest):
      ActiveRecord::RecordNotFound: Couldn’t find FileAttachment with ID=0

    Looks pretty much the same as I’m getting.

    On 9/8/06, s.ross [email protected] wrote:

    Not too comforting, right? I suggest you create a fresh rails project,
    install the plugin from svn, edit the database.yml, then run the tests. That
    way you can reassure yourself that the plugin should be passing its tests. I
    suspect it will pass the tests. Then compare to see what’s different between
    the fresh install and your current project.

    Thanks for the suggestion. I created a new project, installed the
    plugin, edited the database.yml file and ran the tests:

    47 tests, 35 assertions, 0 failures, 39 errors
    rake aborted!
    Command failed with status (1): [/usr/local/bin/ruby -Ilib:test
    "/usr/local…]

    1. Error:
      test_filesystem_size_for_file_attachment(AttachmentTest):
      ActiveRecord::RecordNotFound: Couldn’t find FileAttachment with ID=0

    There are some messages about the most current version of the plugin
    needing edge rails, so I deleted the plugin and installed the 1.1.6
    version. Save errors. (all I need to do is rm -R acts_as_plugin to
    delete the old one, right?)

    If you really get stuck, why not post your question to
    http://rails.techno-weenie.net/?

    I’ll try there too.

    Thanks

    Rather than installing 1.1.6, you might try:

    rake rails:edge:freeze

    It shouldn’t be too different. And yes, to uninstall the plugin rm -Rf
    should work.

    So others may help with this, what OS are you running (Web server
    doesn’t
    really matter if you’re not even passing the tests)? Also, have you
    successfully done anything with sqlite3? Just grasping at straws, but
    maybe you have a bad build?

    John T.-3 wrote:

    Finished in 2.989249 seconds.
    the fresh install and your current project.

    1. Error:

    I’ll try there too.

    Thanks


    View this message in context:
    http://www.nabble.com/Problem-with-acts_as_attachment-plugin-tf2237123.html#a6220434
    Sent from the RubyOnRails Users forum at Nabble.com.

    The different configs are there so you can choose the one that matches
    up
    with your system. I just did the same exact set of steps to see if I
    could
    repro your bug and I get:

    Finished in 2.989249 seconds.

    47 tests, 255 assertions, 0 failures, 0 errors

    Not too comforting, right? I suggest you create a fresh rails project,
    install the plugin from svn, edit the database.yml, then run the tests.
    That
    way you can reassure yourself that the plugin should be passing its
    tests. I
    suspect it will pass the tests. Then compare to see what’s different
    between
    the fresh install and your current project.

    If you really get stuck, why not post your question to
    http://rails.techno-weenie.net/?

    Yes, somebody is reading these.

    Hope this helps.

    John T.-3 wrote:

    test folder of the plugin to only use sqlite3 (I’d figure it would

    1. Error:
      test_filesystem_size_for_file_attachment(AttachmentTest):
      ActiveRecord::RecordNotFound: Couldn’t find FileAttachment with ID=0

    Looks pretty much the same as I’m getting.


    View this message in context:
    http://www.nabble.com/Problem-with-acts_as_attachment-plugin-tf2237123.html#a6219597
    Sent from the RubyOnRails Users forum at Nabble.com.

    On 9/9/06, s.ross [email protected] wrote:

    So others may help with this, what OS are you running (Web server doesn’t
    really matter if you’re not even passing the tests)? Also, have you
    successfully done anything with sqlite3? Just grasping at straws, but
    maybe you have a bad build?

    OS X, and I’ve used sqlite3 without a problem.

    On 9/9/06, John T. [email protected] wrote:

    OS X, and I’ve used sqlite3 without a problem.

    I tried the same test on another system (creating a new rails app,
    install the plugin (1.1.6 version) and run the tests. On this system,
    the tests passed. The difference is, the second system does have
    ImageMagick/Rmagick installed.

    Does the plugin require Imagemagick? I thought it didn’t, but I’m
    thinking that it just might.

    And on yet a third machine (also OS X, without ImageMagick), testing
    gives even different results:

    Started
    …EEE…F.FFE…E…EE…E…FFFF.EE.
    Finished in 6.959831 seconds.

    47 tests, 143 assertions, 7 failures, 10 errors
    rake aborted!
    Command failed with status (1): [/usr/local/bin/ruby -Ilib:test
    "/usr/local…]

    Some passed. (It looks like the ones that failed are the ones that
    would be using ImageMagick)

    All 3 machines had Rails installed the same way, using the Hivelogic
    steps. I’m at a loss and am about to just give up.

    Oops. Got that rake task backwards…

    rake rails:freeze:edge

    John T.-3 wrote:

    Finished in 2.989249 seconds.
    the fresh install and your current project.

    1. Error:

    I’ll try there too.

    Thanks


    View this message in context:
    http://www.nabble.com/Problem-with-acts_as_attachment-plugin-tf2237123.html#a6220474
    Sent from the RubyOnRails Users forum at Nabble.com.

    On 9/9/06, Rick O. [email protected] wrote:

    The tests rely on rmagick. if it’s not installed, there’s nothing to
    resize the images so the tests won’t pass.

    That makes sense. I also assume that this message in the log while
    trying to create a new item:

    Exception working with image: undefined method `columns’ for
    #String:0x22ae4ac

    indicates the missing ImageMagick/rmagick?

    Any idea why creating a new item, in my initial messages and sample
    app, are returning 0 for the id??

    Thanks

    On 9/9/06, John T. [email protected] wrote:

    Any idea why creating a new item, in my initial messages and sample
    app, are returning 0 for the id??

    Thanks

    For anyone else who happens to run into this. Apparently, something
    changed somewhere to cause sqlite3 and ruby to not work (some details
    here:
    http://scottstuff.net/blog/articles/2006/07/01/sqlite-3-and-ruby-finally-working-on-os-x
    )

    I ended up installing SWIG from source (I don’t have Darwinports
    installed), and removed and reinstalled the sqlite3 gem and it’s all
    working again.

    On 9/9/06, John T. [email protected] wrote:

    47 tests, 143 assertions, 7 failures, 10 errors
    rake aborted!
    Command failed with status (1): [/usr/local/bin/ruby -Ilib:test "/usr/local…]

    Some passed. (It looks like the ones that failed are the ones that
    would be using ImageMagick)

    All 3 machines had Rails installed the same way, using the Hivelogic
    steps. I’m at a loss and am about to just give up.

    The tests rely on rmagick. if it’s not installed, there’s nothing to
    resize the images so the tests won’t pass.


    Rick O.
    http://weblog.techno-weenie.net
    http://mephistoblog.com

    On 9/9/06, John T. [email protected] wrote:

    Exception working with image: undefined method `columns’ for #String:0x22ae4ac

    indicates the missing ImageMagick/rmagick?

    Any idea why creating a new item, in my initial messages and sample
    app, are returning 0 for the id??

    Yes, if that’s all you’re getting in the test failures, I wouldn’t
    worry about it. For now, you’ll just miss out on all the swanky
    resizing/thumbnailing aspects without RMagick. The rest of the plugin
    should work though.


    Rick O.
    http://weblog.techno-weenie.net
    http://mephistoblog.com