Topic: Can't call same action from RJS

Hi everyone,

Here's my setup:

My home page has a short list of "articles" in a partial, with a conditional around the link to use link_to, if rendered from the home page, or link_to_remote if rendered from the articles page so I can swap out the HTML for each article via ajax.

My action to display an article is called "read". When I view an article from the home page via "articles/read/permalink", it works fine. I am redirected to the articles page, and it will load. But, when I'm on the articles page and I try to call "read" using an RJS file of the same name, it won't fire "page[:content].replace_html 'foo'" at all.

But, if I add a new action and use RJS to call the new action, it will work. I only need one action - read to retrieve the data I need. What should I be doing to work around this problem?

Thanks for your advice,

Brandon Taylor
Sr. Developer

Dell

Re: Can't call same action from RJS

I resolved this issue with a respond_to block:

respond_to do |format|
    format.html { render }
    format.js
end

This caused Rails to look for an RJS file with my action name, "read" and executed the RJS commands.

Brandon Taylor
Sr. Developer

Dell