# Undefined Method Error in View

**URL:** <https://www.ruby-forum.com/t/undefined-method-error-in-view/74232>\
**Category:** Rails\
**Created:** [February 27, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/undefined-method-error-in-view/74232 "2006-02-27T17:45:27Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bill\_Wilcox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47c2d/32.png) [@Bill\_Wilcox](https://www.ruby-forum.com/u/Bill_Wilcox)\
**Post date:** [February 27, 2006, 5:45pm UTC](https://www.ruby-forum.com/t/undefined-method-error-in-view/74232/1 "2006-02-27T17:45:27Z")

</div>

After messing around with PHP for over a year, I took one look at Ruby  
on Rails and fell in love. But it’s one of those confused “Men are from  
Mars, Women are from Venus” type things…

I’ve written a method which does find\_by\_sql to pick a random row from a  
database. When I call that method I get an “undefined method ‘text’ for  
…” ‘text’ is the name of one of two columns in the database, and  
something I want to display.

I know the SQL works it was lifted from a PHP project, and from a  
command line returns exactly what it should.

What confuses me is what I’m doing in the view. If my view looks like  
this:

\<% for column in Quote.content\_columns %\>

\<%= column.human\_name %\> \<%= column.send(column.name) %\>

\<% end %\>

I get the method error.

However, if my view looks like this:

\<% for column in Quote.content\_columns %\>

\<%= column.human\_name %\>

\<% end %\>

It works, printing out the column names. To me that verifies that the  
sql is right, but I’m missing something when it comes to displaying the  
actual contents in the column ‘text’.

From what I’ve been reading, ActiveRecord should automatically create  
the method ‘text’ in order to display the column data. It’s working  
well enough to output the column name, but what I’m a doing wrong when  
it comes to displaying the data?

Thanks!  
Bill

---

<div class="post-metadata">

**Author:** ![Bill\_Wilcox](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e47c2d/32.png) [@Bill\_Wilcox](https://www.ruby-forum.com/u/Bill_Wilcox)\
**Post date:** [February 28, 2006, 4:48am UTC](https://www.ruby-forum.com/t/undefined-method-error-in-view/74232/2 "2006-02-28T04:48:40Z")

</div>

On Feb 27, 2006, at 9:40 AM, Bill Wilcox wrote:

> I’ve written a method which does find\_by\_sql to pick a random row  
> from a  
> database. When I call that method I get an “undefined method  
> ‘text’ for  
> …” ‘text’ is the name of one of two columns in the database, and  
> something I want to display.

Someone stated earlier how smart people solve their own problems. If  
that’s the case why do I feel like an idiot? Well, today I learned  
more about how Active Record functions and more importantly, how to  
use the built in syntax (instead of my old sql querries) to do what I  
want.

[http://wiki.rubyonrails.com/rails/pages/HowtoSelectRandomRecords](http://wiki.rubyonrails.com/rails/pages/HowtoSelectRandomRecords)

Okay, next bit of database interactivity I promise to do the rails  
way first…

Bill
