Hello!
I’m trying to get image uploads to work with file_column, and thought
I almost had it when I stumbled on a really strange error I can’t
figure out. No other post here seems to deal with it either.
The create and edit views for my object “Item” (I’m a newbie at ruby/
rails, so pardon my vocab
display the uploaded image just fine, but
when I go back to the index, the page dies because it tried to invoke
picture_relative_path on nil. No idea why the image string suddenly
becomes nil, seems to me that it shouldn’t be possible… attaching
error and code around it. Any help GREATLY appreciated, just holler if
any additional info would make it easier to diagnose. Hopefully the
hive mind is sharper than my googling 
--------Error output----------------
Showing items/index.html.erb where line #14 raised:
You have a nil object when you didn’t expect it!
The error occurred while evaluating nil.picture_relative_path
Extracted source (around line #14):
11:
12: <%=h item.name %> |
13: <%=h item.category %> |
14: <%= image_tag url_for_file_column(“item”, “picture”,
“normal”) %> |
15: <%= link_to ‘Show’, item %> |
16: <%= link_to ‘Edit’, edit_item_path(item) %> |
17: <%= link_to ‘Destroy’, item, :confirm => ‘Are you
sure?’, :method => :delete %> |
Check out the documentation:
- in a view, "<%= url_for_file_column ‘entry’, ‘image’ %> will create
an URL to access the
uploaded file. Note that you need an Entry object in the instance
variable @entry for this
to work.
So the line in your index view:
<%= image_tag url_for_file_column(“item”, “picture”,
“normal”) %>
Is in-fact is trying to invoke:
@item.picture_relative_path
hence why you are getting evaluating nil error
Try this instead, pass the actual variable without quotes:
<%= image_tag url_for_file_column(item, “picture”,
“normal”) %>
Admittedly I probably wouldn’t use file_column these days. Paperclip
is the defacto standard:
http://github.com/thoughtbot/paperclip/tree/master
Checkout the Ruby Tool Box which will give you sense of the defacto
plugins:
http://ruby-toolbox.com/
HTH,
Nicholas
You might also consider attachment_fu (de other facto
as a viable
replacement for FileColumn.