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


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 :


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 !


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.


On May 13, 9:10 am, Leo K. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs