# Odd error with file\_column and relative\_path

**URL:** <https://www.ruby-forum.com/t/odd-error-with-file-column-and-relative-path/170502>\
**Category:** Rails\
**Created:** [June 18, 2009, 9:32am UTC](https://www.ruby-forum.com/t/odd-error-with-file-column-and-relative-path/170502 "2009-06-18T09:32:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Per\_Fagrell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@Per\_Fagrell](https://www.ruby-forum.com/u/Per_Fagrell)\
**Post date:** [June 18, 2009, 9:32am UTC](https://www.ruby-forum.com/t/odd-error-with-file-column-and-relative-path/170502/1 "2009-06-18T09:32:08Z")

</div>

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 %\>

---

<div class="post-metadata">

**Author:** ![Per\_Fagrell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@Per\_Fagrell](https://www.ruby-forum.com/u/Per_Fagrell)\
**Post date:** [June 18, 2009, 4:18pm UTC](https://www.ruby-forum.com/t/odd-error-with-file-column-and-relative-path/170502/2 "2009-06-18T16:18:48Z")

</div>

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:

> **[GitHub - thoughtbot/paperclip at master](https://github.com/thoughtbot/paperclip/tree/master)**
>
> master

Checkout the Ruby Tool Box which will give you sense of the defacto  
plugins:

> **[The Ruby Toolbox - Know your options!](https://www.ruby-toolbox.com/)**
>
> Explore and compare open source Ruby libraries

HTH,  
Nicholas

---

<div class="post-metadata">

**Author:** ![Per\_Fagrell](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/a698b9/32.png) [@Per\_Fagrell](https://www.ruby-forum.com/u/Per_Fagrell)\
**Post date:** [June 18, 2009, 6:01pm UTC](https://www.ruby-forum.com/t/odd-error-with-file-column-and-relative-path/170502/3 "2009-06-18T18:01:45Z")

</div>

You might also consider attachment\_fu (de other facto 🙂 as a viable  
replacement for FileColumn.
