# File\_column question from new ror user

**URL:** <https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096>\
**Category:** Rails\
**Created:** [November 13, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096 "2007-11-13T18:47:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 13, 2007, 6:47pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/1 "2007-11-13T18:47:31Z")

</div>

Hi All,

I am new in using Ruby on Rails, I have a problem about display a pic by  
using file\_column.  
Wish someone can help me, thx

In below code, I want to use @entry to store the Entry object which with  
ID=5. (I have already created a entry with ID=5.)

And then I use display.rhtml to display the relative pic  
But I get this error message

* * *

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.image\_relative\_path  
Extracted source (around line #1):

## 1: \<%= image\_tag url\_for\_file\_column ‘entry’, ‘image’ ,‘thumb’%\>

Below are the codes I used.  
==Controller===  
def display  
@entry = Entry.find(5)  
end

==display.rhtml====  
\<%= image\_tag url\_for\_file\_column ‘entry’, ‘image’ ,‘thumb’%\>

Below code is copy from a site which teach how to use file\_column.  
It’s work !!! I write the other code similar to it, but my code is not  
work

==Controller===  
def show  
@entry = Entry.find(params[:id])  
end

==show.rhtml===  
\<% for column in Entry.content\_columns %\>

**\<%= column.human\_name %\>:** \<%=h @entry.send(column.name) %\>  
Original: \<%= image\_tag url\_for\_file\_column 'entry', 'image' %\>  
thumb: \<%= image\_tag url\_for\_file\_column 'entry', 'image' ,'thumb'%\>  
medium: \<%= image\_tag url\_for\_file\_column 'entry', 'image' ,'medium'%\>

\<% end %\> \<%= link\_to 'Edit', :action =\> 'edit', :id =\> @entry %\> | \<%= link\_to 'Back', :action =\> 'list' %\>

---

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 13, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/2 "2007-11-13T19:38:02Z")

</div>

Hi,

My guess is that you need to put parenthesis around the parameters of  
url\_for\_file\_column. So it would look like \<%= image\_tag  
url\_for\_file\_column( ‘entry’, ‘image’ ,‘thumb’ ) %\>

Otherwise Rails can’t know if those parameters are for the image\_tag  
method or for the other one.

- Jone

---

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 13, 2007, 7:49pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/3 "2007-11-13T19:49:47Z")

</div>

Hi Jouni,

Thx for your help, but the code still not work.

After read some post in the site, I find that it’s required to use @ to  
define the local variable from controller and past it to the view.  
And then, I try to change code to below.  
But, the other error message is diplayed.

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.each  
Extracted source (around line #1):

1: \<% for @entry in @entries %\>  
2: \<%= image\_tag url\_for\_file\_column(‘entry’, ‘image’ ,‘thumb’)%\>  
3:  
4: \<% end %\>

==Controller===  
def display  
@entries = Entry.find(:all)  
end

==display.rhtml====  
\<% for @entry in @entries %\>  
\<%= image\_tag url\_for\_file\_column(‘entry’, ‘image’ ,‘thumb’)%\>  
\<% end %\>

Stanley

Jouni Pohjolainen wrote:

> Hi,
> 
> My guess is that you need to put parenthesis around the parameters of  
> url\_for\_file\_column. So it would look like \<%= image\_tag  
> url\_for\_file\_column( ‘entry’, ‘image’ ,‘thumb’ ) %\>
> 
> Otherwise Rails can’t know if those parameters are for the image\_tag  
> method or for the other one.
> 
> - Jone

---

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 13, 2007, 8:44pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/4 "2007-11-13T20:44:26Z")

</div>

are you sure, that @entries can find something?

put something like  
logger.info “foo: #{@entries.size}”  
in your controller and check development.log

---

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 13, 2007, 9:08pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/5 "2007-11-13T21:08:37Z")

</div>

Hi Thorsten,

Thx for your feedback

I have add this logger.info to the display method in the controller  
def display  
logger.info(“haha”)  
@entries = Entry.find(:all)  
logger.info(“foo: #{@entries.size}”)  
end

The log show nothing. But I add the same log code in the method “list”  
which generated by scaffold,  
It can show the correct log.

def list  
logger.info(“haha”)  
@entry\_pages, @entries = paginate :entries, :per\_page =\> 10  
logger.info(“foo: #{@entries.size}”)  
end

Why ???

Thanks a lot  
Stanley

Thorsten M. wrote:

> are you sure, that @entries can find something?
> 
> put something like  
> logger.info “foo: #{@entries.size}”  
> in your controller and check development.log

---

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 13, 2007, 9:17pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/6 "2007-11-13T21:17:36Z")

</div>

Hi Thorsten,

Finally, I solve the problem.

I create another method with the other name, but use the same code.  
It’s WORK !!!

Maybe the name “display” is a reserve word in RoR, and cannot be use as  
the method name

Anyway, thx a lot

Stanley

Stanley Wong wrote:

> Hi Thorsten,
> 
> Thx for your feedback
> 
> I have add this logger.info to the display method in the controller  
> def display  
> logger.info(“haha”)  
> @entries = Entry.find(:all)  
> logger.info(“foo: #{@entries.size}”)  
> end
> 
> The log show nothing. But I add the same log code in the method “list”  
> which generated by scaffold,  
> It can show the correct log.
> 
> def list  
> logger.info(“haha”)  
> @entry\_pages, @entries = paginate :entries, :per\_page =\> 10  
> logger.info(“foo: #{@entries.size}”)  
> end
> 
> Why ???
> 
> Thanks a lot  
> Stanley
> 
> Thorsten M. wrote:
> 
> > are you sure, that @entries can find something?
> > 
> > put something like  
> > logger.info “foo: #{@entries.size}”  
> > in your controller and check development.log

---

<div class="post-metadata">

**Author:** ![kamhei82](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/a88e4f/32.png) [@kamhei82](https://www.ruby-forum.com/u/kamhei82)\
**Post date:** [November 14, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/file-column-question-from-new-ror-user/120096/7 "2007-11-14T17:44:16Z")

</div>

Yeah, you are right about it being reserved word in Rails. Well  
actually not reserved, but reported to cause problems. Good site to  
check those reserved and problematic names is this.  
[http://wiki.rubyonrails.org/rails/pages/ReservedWords](http://wiki.rubyonrails.org/rails/pages/ReservedWords)
