# How to pass values to a controller

**URL:** <https://www.ruby-forum.com/t/how-to-pass-values-to-a-controller/187576>\
**Category:** Rails\
**Created:** [April 26, 2010, 6:46am UTC](https://www.ruby-forum.com/t/how-to-pass-values-to-a-controller/187576 "2010-04-26T06:46:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [April 26, 2010, 6:46am UTC](https://www.ruby-forum.com/t/how-to-pass-values-to-a-controller/187576/1 "2010-04-26T06:46:11Z")

</div>

see i defined one method called campaign in the model and through a  
url i am tryong to pass two parameters like user\_id and campaign\_id  
into a method called mail\_open\_count. how i can pass 2 that method.

def campaign(campaign)  
@campaign\_id = "[#{campaign.email\_campaign\_content.campaign\_id}] "  
@user\_id = "[#{campaign.user\_id}] "  
setup\_email(campaign)  
mail\_template = campaign.active\_email\_template  
template = Liquid::Template.parse(mail\_template.body)  
body :body =\> template.render(“bgcolor1” =\>  
mail\_template.colours[:colour1],“bgcolor2” =\>  
mail\_template.colours[:colour2],“bgcolor3” =\>  
mail\_template.colours[:colour3])\<\< @user\_id \<\< @campaign\_id \<\< “”  
whre is user count is defined in routel like this

map.usercount “usercount”, :controller =\> “campaigns”, :action =\>  
“save\_for\_email\_opens”

if i wanted the parameters user\_id and campaign id to store into a  
table named

campaign\_mail\_count how can i write the method in d controller

---

<div class="post-metadata">

**Author:** ![murfhy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@murfhy](https://www.ruby-forum.com/u/murfhy)\
**Post date:** [April 26, 2010, 8:52am UTC](https://www.ruby-forum.com/t/how-to-pass-values-to-a-controller/187576/2 "2010-04-26T08:52:54Z")

</div>

Tony A. wrote:

> see i defined one method called campaign in the model and through a  
> url i am tryong to pass two parameters like user\_id and campaign\_id  
> into a method called mail\_open\_count. how i can pass 2 that method.
> 
> def campaign(campaign)  
> @campaign\_id = "[#{campaign.email\_campaign\_content.campaign\_id}] "  
> @user\_id = "[#{campaign.user\_id}] "  
> setup\_email(campaign)  
> mail\_template = campaign.active\_email\_template  
> template = Liquid::Template.parse(mail\_template.body)  
> body :body =\> template.render(“bgcolor1” =\>  
> mail\_template.colours[:colour1],“bgcolor2” =\>  
> mail\_template.colours[:colour2],“bgcolor3” =\>  
> mail\_template.colours[:colour3])\<\< @user\_id \<\< @campaign\_id \<\< “”  
> whre is user count is defined in routel like this
> 
> map.usercount “usercount”, :controller =\> “campaigns”, :action =\>  
> “save\_for\_email\_opens”
> 
> if i wanted the parameters user\_id and campaign id to store into a  
> table named
> 
> campaign\_mail\_count how can i write the method in d controller

Hi,

You can try do it like to:  
link\_to “hello”, campain\_path(:user\_is =\> 4, :campain\_id =\> 2)

Greg
