Hi all I''d like to call some controller methods from other controller methods after first modifying the params hash. Class MyController < ApplicationController def quirky_method if condtion do_stuff else params.merge "some_key" => "here is some new data" another_controller_method end end the problem ive got is that the new data in the hash isn''t available inside ''another_controller_method''. i''ve also tried ''self.params'' and ''@params'', but doesnt seem to work -whats the best way to approach this? thx glenn --~--~---------~--~----~------------~-------~--~----~ 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 2/11/07, glenn <glenn-H7U4i/pZ250d9SLi6J12ItHuzzzSOjJt@public.gmane.org> wrote:> > Hi all > > I''d like to call some controller methods from other controller > methods after first modifying the params hash. > > Class MyController < ApplicationController > def quirky_method > if condtion > do_stuff > else > params.merge "some_key" => "here is some new data" > another_controller_method > end > end > > the problem ive got is that the new data in the hash isn''t available > inside ''another_controller_method''. i''ve also tried ''self.params'' and > ''@params'', but doesnt seem to work -whats the best way to approach > this?The reason the params aren''t updated is that #merge is not a destructive method. It returns a new Hash which you''re just throwing away (not referencing or assigning to a variable). There is a destructive version, #merge!, which does what you want. Just add the exclamation point, and you''ll get what you''re expecting. But, I think what you should probably do is make another_controller_method accept the parameters it''s expecting as explicit arguments and call it like that. Munging params is bound to lead to some messes later on. Chad --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> The reason the params aren''t updated is that #merge is not a > destructive method. It returns a new Hash which you''re just throwing > away (not referencing or assigning to a variable). > > There is a destructive version, #merge!, which does what you want. > Just add the exclamation point, and you''ll get what you''re expecting. >ok - a vital detail - thanks chad - dangers of learning a language along with a toolkit implimented in it> But, I think what you should probably do is make > another_controller_method accept the parameters it''s expecting as > explicit arguments and call it like that. Munging params is bound to > lead to some messes later on.good advice - thanks, what i ended up doing in end thanks again chad glenn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---