Welcome Guest | Login

has_one, belongs_to causing TemplateError

First time trying to deploy an app having some trouble.

Basically, I have ebook that has_one :ebook_cover and has_one :ebook_download.  Both ebook_cover and ebook_download belongs_to :ebook. Pretty simple, right?

A template error pops up when i try to get the ebook.ebook_download.  Look at the debug(ebook): http://pastie.caboo.se/87522

Strangely though, ebook.ebook_cover works fine.  If you want to see my production.log, check out   http://pastebin.ca/657036

Btw, this works fine in the localhost.  I'm using a logger so it might look a little diff, however, the same error still shows:

Aug 14 10:25:34 owen rails[5884]: ActionView::TemplateError (exit) on
line #8 of app/views/home/index.rhtml:5: <ul>
6:      <li><%= link_to(@ebook.title, :controller => "ebooks", :action => "show", :id => @ebook) %></li>
7:      <li><%= image_tag(@ebook.ebook_cover.public_filename(:thumb) ) %></li>
8:      <li><%= debug(@ebook.ebook_download) %></li>
What is it I'm doing wrong?

2007-08-14 11:25 AM

Ramon Tayag
Try something like

<%= @ebook.ebook_download.some_attribute %>

Does that work?

2007-08-14 06:27 PM

I tried

<%= @ebook.ebook_download.ebook_id %>

but nope, it doesn't work :(  I even tried

<%= EbookDownload.find(1).ebook_id %>

to see if it was a problem of getting from @ebook to ebook_download, but nope, I still get the same error.

2007-08-14 07:55 PM

Ramon Tayag
Ok - Can you paste in the entire controller action, view, and model ?  That's really what we need to help further.  Sorry for the trouble.  

2007-08-15 02:38 AM

Thanks for all your help William.  I found out something new: I got into the console and tried something and got this error:

irb(main):001:0> download = EbookDownload.find(:first)
NameError: uninitialized constant EbookDownload
       from (irb):1
Either way, here's the link to my model, controller, and the view:http://pastie.caboo.se/87872

I didn't bother pasting the EbookDownload controller itself (if you see the pastie I'm using another controller) since in this case I'm not even accessing the controller.

2007-08-15 05:08 AM

Ramon Tayag
Hmm.. other code in the irb acts funny too:

irb(main):002:0> ebook = Ebook.find(:first)
NameError: uninitialized constant Ebook
       from (irb):2
       from :0
However, @ebook is accessible in the view though, since when I remove the EbookDownload.find(:first) line things work.

2007-08-15 05:12 AM

Ramon Tayag
Ok, I think I've nailed the problem.

I put a line even if I didn't need it:
:processor => "MiniMagick"

and it worked!

My theory:
If i don't specify a processor, the server picks image_science as the
default, which is why image_science comes out in the error log.  It
works on my local box because it doesn't choose an image processor.
But by picking image_science, the server breaks the app.

So i'm hoping it works, but i'll just specify the processor even if i
won't do any image manipulation for that object.

2007-08-15 11:38 PM

Ramon Tayag
Finally, I solved the problem.   I found out in the end it has nothing to do with belongs_to, has_many, or any of those.  It was the model itself.  Just in case some of you get stuck on the same thing, here's the problem:

If you're using attachment_fu, in a model where you don't even need any image processing, _specify an image processor_. HostingRails by default picks image_science and this causes an error.  I used MiniMagick and it worked.

Goodluck!

2007-08-16 02:41 AM

Ramon Tayag

Hello Guest! In order to post you must be an active client with us, please log in or sign up.