Topic: Trouble with db query

I'm just starting out and having problems creating a query.
I want to display the contents of a field in my database table, I have the row available as params[:id] and the column as params[:field].
I tried:
deal = Deal.find(params[:id])
render_text deal.params[:field]

But that doesn't work. If I specify a column name, e.g render_text, it works, but I want to be able to base the column name of that param[:field], not have it fixed.

Thank you for any help,

Re: Trouble with db query

There are a couple other ways ActiveRecord allows you to access the column. One way is like: deal['my_column']. Try:

deal = Deal.find(params[:id])
render_text deal[params[:field]]

Railscasts - Free Ruby on Rails Screencasts

Re: Trouble with db query

Works perfectly, thank you!

Last edited by JasonK (2006-08-15 13:32:56)