# Passing params between controller methods

**URL:** <https://www.ruby-forum.com/t/passing-params-between-controller-methods/85264>\
**Category:** Rails\
**Created:** [February 12, 2007, 3:50am UTC](https://www.ruby-forum.com/t/passing-params-between-controller-methods/85264 "2007-02-12T03:50:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [February 12, 2007, 3:50am UTC](https://www.ruby-forum.com/t/passing-params-between-controller-methods/85264/1 "2007-02-12T03:50:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [February 12, 2007, 6:00am UTC](https://www.ruby-forum.com/t/passing-params-between-controller-methods/85264/2 "2007-02-12T06:00:19Z")

</div>

On 2/11/07, glenn [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> 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

---

<div class="post-metadata">

**Author:** ![glenn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/4bbf92/32.png) [@glenn](https://www.ruby-forum.com/u/glenn)\
**Post date:** [February 12, 2007, 12:14pm UTC](https://www.ruby-forum.com/t/passing-params-between-controller-methods/85264/3 "2007-02-12T12:14:46Z")

</div>

> 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
