Link_to_remote and render

Can I reload a page loaded via link_to_remote? I do this in my controller:

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

But when captchas is wrong, it does not display the form that is inside the new template. By the way, in the web server log it shows that the temp has been visualized.

Thanks!

UPDATED: Today I changed the render to:

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

But it makes me refresh the page called link_to_remote, not the page that was opened via link_to_remote

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

+4
source share
2 answers

You need render :update , not render :action .

I do this all the time. As in the answer from jdl, you can use inline rjs (you don’t know if this term is correct) to display 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 
+4
source

Something like this should do what you want.

 render :update do |page| page << 'window.location.reload()' end 
+1
source

Source: https://habr.com/ru/post/1277766/


All Articles