# How to pass argument to Controler method. (RoR +AJAX)

**URL:** <https://www.ruby-forum.com/t/how-to-pass-argument-to-controler-method-ror-ajax/137478>\
**Category:** Rails\
**Created:** [May 13, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/how-to-pass-argument-to-controler-method-ror-ajax/137478 "2008-05-13T16:10:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynoobie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rubynoobie](https://www.ruby-forum.com/u/rubynoobie)\
**Post date:** [May 13, 2008, 4:10pm UTC](https://www.ruby-forum.com/t/how-to-pass-argument-to-controler-method-ror-ajax/137478/1 "2008-05-13T16:10:43Z")

</div>

Hi

My problem is the following.  
I have to describe a sort of a “news” page. (I just have to give the  
basic architecture)

I want to refresh a

 acording to the name of the link cliked.

my code looks like this :

* * *

\<%= link\_to\_remote “sports”,  
:update =\> ‘news\_div’,  
:url =\> {:action =\> “getinfo”} %\>.

\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

I have a “getinfo” method in my controller to get the news and fill the  
div. But how do I pass an argument to “getinfo” to get specific news?

I would like to do for example in pseudocode :

getinfo(“sports”)  
getinfo(“international”)  
getinfo(“finance”)

Basicaly I want to pass the name of the link as argument to the  
“getinfo” method.

can anyone show me:  
the syntax for my “link\_to\_remote” link and the syntax for the getinfo  
method of my controller so that it allows to take an argument?

this would be a great help !

thanx

---

<div class="post-metadata">

**Author:** ![rubynoobie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/c2a13f/32.png) [@rubynoobie](https://www.ruby-forum.com/u/rubynoobie)\
**Post date:** [May 13, 2008, 6:34pm UTC](https://www.ruby-forum.com/t/how-to-pass-argument-to-controler-method-ror-ajax/137478/2 "2008-05-13T18:34:35Z")

</div>

Try adding :with =\> “‘variable=’ + value” after the URL info. You can  
code the variable name (such as “section=”), but you’ll need to find a  
way to get the section name into the place of “value” above. That  
will depend on how you’re creating your links.

In the end, this should (hopefully) work for one link:

\<%= link\_to\_remote “sports”,  
:update =\> ‘news\_div’,  
:url =\> {:action =\> “getinfo”},  
:with =\> “‘section=’ + ‘sports’” %\>

Looking at it again, you could probably use :with =\>  
“section=#{link.section}” for better readability.

-Kyle

On May 13, 9:10 am, Leo K. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
