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

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

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?