Forum: Ruby Undefined Method

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
William Wilcox (Guest)
on 2006-02-27 07:14
(Received via mailing list)
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 %>
<p>
  <%= column.human_name %> <%= column.send(column.name) %>
</p>
<% end %>

I get the method error.

However, if my view looks like this:

<% for column in Quote.content_columns %>
<p>
  <%= column.human_name %>
</p>
<% 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
This topic is locked and can not be replied to.