I took a look at various posts like this How to use the link_to helper to open a popup? but I wasn't able to make it work.
Here is my code:
in the application.js
I included this code:
$('a[data-popup]').live('click', function(e) {
window.open( $(this).attr('href'), "Popup", "height=600, width=600" );
e.preventDefault();
});
in the assessment_controller.rb
I included this method:
def open_second_app
respond_to do |format|
format.js
end
end
in the assessments index page index.html.erb
I included the link:
<div>
<%= button_to 'New', new_assessment_path, method: :get %>
<%= button_to 'Home', root_path, method: :get %>
<%= link_to( 'Open Second Application', open_second_app_path, 'data-popup' => true ) %>
</div>
I also have a open_second_app.js.erb
file containing this single line:
window.open (<%= open_second_app_path %>, "Second Appllication Window", "width=600,height=600");
When I click the link, I am getting this error:
Showing /Users/liviu-mac/ror/levi-test-01/app/views/assessments/index.html.erb where line #34 raised:
undefined local variable or method `open_second_app_path' for #<#<Class:0x007fe3c6fa4040>:0x007fe3c40ae4c0>
The main application is running as localhost:3000
.
The second application is running as localhost:3001
.
What I am doing wrong here?