Popup / New Window + Redirect_to + Rails

Can I redirect to some URL from the controller and open the URL in a new window at the same time?

+3
source share
3 answers

Not quite out of controller action.

Forwarding is an HTTP response with a status code of 301/302 and an empty body in Rails. Since the body is empty, you have no way to enable additional processing for the browser (e.g. javascript, etc., to open a new window).

Assuming you have a controller action caused by a hyperlink on another page, the best option would be to open this in a new window. Then the redirect target will be displayed.

, , ( ), javascript ,

+6

@madlep " , "

. !

:

<%= link_to "Buy this product", buy_path, target: "_blank" %>

:

def buy
  ...
  redirect_to link
end
+3

... ( , ...) :

<%= link_to '', {:controller => 'assignments', :action => 'overall_report_gen', :evaluator_relations => @evaluator_relations}, :target => '_blank', :id => 'reporte' %>

<script language="JavaScript">
  document.getElementById('reporte').click();
</SCRIPT>

'' link_to ,

:target => '_blank' ,

:id => 'reporte' , javascript.

link_to javascript,

javascript link_to,

+1
source

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


All Articles