Rjs rails to execute?

I have the following:


<%= javascript_include_tag :defaults %>

<%= render :partial => 'menu' %>

menu partial:

<%= link_to_remote “Generate Text”,
:update => ‘myrandom’,
:url => { :action => ‘myrandom’ } %>

myrandom :

def myrandom
render_text “here is some text”


page.visual_effect :highlight, ‘myrandom’, :duration => 3

When I click action, the text is rendered, however the rjs does not
seem to take effect, I was trying to get rjs working in a more
complicated scenario, but hopefully if I can understand why it is not
working here I can apply it to my other scenario.

Any pointers appreciated.




You can only render once per action. Since you are explicitly rendering
text from your myrandom action, the rjs template is never looked at.
Anytime you put an explicit render call in your action, you
short-circuit it
from looking at templates. If there aren’t any render calls in your
upon exiting your action method ActionController will first look for a
myrandom.rhtml file to render. If that file exists, it will render that
template and send the response. If it doesn’t exist, it will look for a
myrandom.rjs template, render it, and send a response. (Failing all of
that, you’ll get a template does not exist error.)

In your example, assuming you do not have a myrandom.rhtml file in the
folder, it will render the rjs template if you simply remove the call to
render_text (and leave the action empty).

To have the text inserted into the DOM in the

have to change the myrandom.rjs template to:

page.replace_html ‘myrandom’, ‘here is some text’
page.visual_effect :highlight, ‘myrandom’, :duration => 3

Hope that helps.

On Thu, Jul 06, 2006 at 08:55:04AM -0600, Jeremy H. wrote:

that, you’ll get a template does not exist error.)

Hope that helps.

Wonderful, thank you for the explanation, this is now functioning the
way I had hoped.

Thank you.

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