views:

1725

answers:

2

Is it possible to reload a page that was loaded thru link_to_remote? I'm doing this in my controller:

def create
 if captchas_verified
  do_something
 else
  render :action=>'new'
end

But when the captchas is wrong, it do not render a form that is inside of the new template. By the way, in the webserver log, it shows that the templades was rendered.

Thanks!

UPDATED: Today i changed the render to:

render(:update) { |page| page.call 'location.reload' }

But it makes me update the page that called the link_to_remote not the page that was opened thru the link_to_remote

UPDATED 2: I fixed using page.replace_html "mydiv", :partial => "new" instead of page.call 'location.reload'

A: 

Something like this should do what you want.

render :update do |page| page << 'window.location.reload()' end
jdl
+2  A: 

You need to render :update, rather than render :action.

I do this sort of thing all the time. Similar to the response from jdl you can use inline rjs (don't know if that's the right term) to render the page.

render(:update) do |page|
  page.replace_html("div_to_update", :partial => "name_of_template", :object => @object)
  page << "alert('javascript can be inserted here as well')"
end
salt.racer