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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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> 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 > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Feb 10, 9:54 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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. > > 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. > > ThanksI think this will do what you want: faq[column_name] = params[:value] --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Feb 10, 7:18 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Feb 10, 9:54 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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. > > > 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 think this will do what you want: > > faq[column_name] = params[:value]--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <phil-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> wrote:> > 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 > > > On Feb 10, 7:18 pm, bigbanger <bigbanger...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > On Feb 10, 9:54 am, phil <p...-o0Q4Q1ys/oVBDgjK7y7TUQ@public.gmane.org> 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. > > > > > 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 think this will do what you want: > > > > faq[column_name] = params[:value] > > >-- Ryan Bigg http://www.frozenplague.net Feel free to add me to MSN and/or GTalk as this email. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---