Method from string?

I am sure this is doable but I can’t find a specific example and my
brain is frazzled.
Basically, I am doing a whole load of in-place editing and need
methods to support the updates.

Here is what I am doing now:

def set_blog_website
faq = Faq.find(params[:id])
faq.blog_website = params[:value]
faq.save!
@faq = faq
do_ret
end

Surely there is a generic way I can do this so that I can do something
like
def set_blog_website
@faq = update_column(:blog_website)
end

def update_column(column_name)
faq = Faq.find(params[:id])
faq.column_name = params[:value]<<-- here’s what I don’t know how to
do!
faq.save!
@faq = faq
do_ret
end

Any ideas on how I could set the attribute? Faq is an
ActiveRecord::Base object.

Thanks

On 10 Feb 2008, at 17:54, phil wrote:

I am sure this is doable but I can’t find a specific example and my
brain is frazzled.
Basically, I am doing a whole load of in-place editing and need
methods to support the updates.

Take a look at the update_attribute method

Fred

On Feb 10, 9:54 am, phil [email protected] wrote:

faq.save!

def update_column(column_name)

Thanks

I think this will do what you want:

faq[column_name] = params[:value]

Thanks guys - I found this does the trick:

def set_column(column_name)
faq = Faq.find(params[:id])
faq.update_attribute(column_name, params[:value])
@faq = faq
do_ret
end

Why aren’t you just defining it as @faq at the start? That would get rid
of
the needeless definition of the local variable “faq” and the line where
you
tell it the instance is the same as the local.

What is do_ret?

On Feb 11, 2008 11:58 PM, phil [email protected] wrote:

Here is what I am doing now:
like
do_ret


Ryan B.

Feel free to add me to MSN and/or GTalk as this email.