# Url\_for\_file\_column nil

**URL:** <https://www.ruby-forum.com/t/url-for-file-column-nil/49636>\
**Category:** Rails\
**Created:** [December 7, 2005, 2:55am UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636 "2005-12-07T02:55:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![beattie.mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f0a364/32.png) [@beattie.mark](https://www.ruby-forum.com/u/beattie.mark)\
**Post date:** [December 7, 2005, 2:55am UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636/1 "2005-12-07T02:55:44Z")

</div>

Hi,

Firstly, thanks to Sebastian K. for an excellent plugin! It works  
marvellously for uploading and resizing images, but I’m getting the  
dreaded  
url\_for\_file\_column returns nil error.

Using:  
file\_column 0.3.1  
Rails 0.14.3  
Ruby 1.8.2-1  
Debian Sarge

I am using an instance variable as required in my view.  
image\_relative\_path  
also returns nil. Any pointers?

new.rhtml:  
\<%= file\_column\_field “recipe”, “image” %\>

show.rhtml:  
\<%= image\_tag url\_for\_file\_column(“recipe”, “image”) %\>

controller:  
@recipe = Recipe.find(params[:id])  
(and is confirmed not to be nil)

NoMethodError:  
You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.first

thanks

–

Mark B.  
Easy Schedule Management  
[http://easy-online-schedule.com](http://easy-online-schedule.com)

---

<div class="post-metadata">

**Author:** ![beattie.mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f0a364/32.png) [@beattie.mark](https://www.ruby-forum.com/u/beattie.mark)\
**Post date:** [December 7, 2005, 3:16am UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636/2 "2005-12-07T03:16:02Z")

</div>

Hello Mark,

2005/12/6, Mark B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Firstly, thanks to Sebastian K. for an excellent plugin! It works  
> marvellously for uploading and resizing images, but I’m getting the dreaded  
> url\_for\_file\_column returns nil error.

Is it possible that @recipe.image is nil ? If that’s the case, then  
that is your problem. You have to code around it:

\<% if @recipe.image.nil? then -%\>  
_No image_  
\<% else -%\>  
\<%= image\_tag url\_for\_file\_column … %\>  
\<% end -%\>

---

<div class="post-metadata">

**Author:** ![beattie.mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f0a364/32.png) [@beattie.mark](https://www.ruby-forum.com/u/beattie.mark)\
**Post date:** [December 7, 2005, 3:20am UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636/3 "2005-12-07T03:20:07Z")

</div>

Hello FranÃ§ois,

On Wednesday 07 December 2005 11:13 am, Francois B. wrote:

> Is it possible that @recipe.image is nil ? If that’s the case, then  
> that is your problem. You have to code around it:

Yes, it is nil, which is exactly the problem - this is for a @recipe for  
which  
an image has been uploaded, resized, and saved by file\_column.

I had exactly that same code in place which resulted in no images being  
displayed at all. Any ideas about where I should be looking for clues?

thanks

–

Mark B.  
Easy Schedule Management  
[http://easy-online-schedule.com](http://easy-online-schedule.com)

---

<div class="post-metadata">

**Author:** ![beattie.mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f0a364/32.png) [@beattie.mark](https://www.ruby-forum.com/u/beattie.mark)\
**Post date:** [December 7, 2005, 4:37am UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636/4 "2005-12-07T04:37:03Z")

</div>

On Wednesday 07 December 2005 12:02 pm, Francois B. wrote:

> nil, then your image was never put in the DB in the first place.

Ah, yes I kinda missed that point somehow - call me stupid but the  
remedy for  
me was to make sure the table actually had a column called “file”…

Could I just as easily have two files associated with an object, such as  
an  
image and an attachment of unknown type using 2 file\_column declarations  
in  
the model assuming it’s table has a field to store the filename of each?

class Foo \< ActiveRecord::Base  
file\_column :image, :magick =\> { :geometry =\> “640x480\>” }  
file\_column :attachment  
end

Sorry to have bothered you, and thanks again.

–

Mark B.  
Easy Schedule Management  
[http://easy-online-schedule.com](http://easy-online-schedule.com)

---

<div class="post-metadata">

**Author:** ![beattie.mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f0a364/32.png) [@beattie.mark](https://www.ruby-forum.com/u/beattie.mark)\
**Post date:** [December 7, 2005, 1:47pm UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636/5 "2005-12-07T13:47:10Z")

</div>

Hi Mark,

I’m glad you like the plugin…

On 12/7/05, Mark B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Could I just as easily have two files associated with an object, such as an  
> image and an attachment of unknown type using 2 file\_column declarations in  
> the model assuming it’s table has a field to store the filename of each?
> 
> class Foo \< ActiveRecord::Base  
> file\_column :image, :magick =\> { :geometry =\> “640x480\>” }  
> file\_column :attachment  
> end

yes, that works. You’ll need two different columns in your database  
and two different file upload fields, though.

Sebastian

---

<div class="post-metadata">

**Author:** ![beattie.mark](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f0a364/32.png) [@beattie.mark](https://www.ruby-forum.com/u/beattie.mark)\
**Post date:** [December 7, 2005, 4:04am UTC](https://www.ruby-forum.com/t/url-for-file-column-nil/49636/6 "2005-12-07T04:04:38Z")

</div>

2005/12/6, Mark B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> On Wednesday 07 December 2005 11:13 am, Francois B. wrote:
> 
> > Is it possible that @recipe.image is nil ? If that’s the case, then  
> > that is your problem. You have to code around it:
> 
> Yes, it is nil, which is exactly the problem - this is for a @recipe for which  
> an image has been uploaded, resized, and saved by file\_column.

Hmmm, that’s bad. Try to open the Rails console and check the recipe  
manually:  
ruby script/console  
r = Recipe.find(ID)  
r.image

r.image should return the path to the image. If that comes back as  
nil, then your image was never put in the DB in the first place.  
Check the place where you upload and add debugging information there.

You might also want to add an after\_save callback to print the path to  
the image, at least temporarily.

Additionaly, unit testing Recipe image uploading might be a good idea.

Hope that helps !
