neelabh
neelabh

Reputation: 577

Opening a new browser tab from rails action in the controller

so i have a Exam controller. Now the the file for it has a jqgrid (index.html.erb )on it. One clicks on the grid row and i have set upped the javascript for handling the event. it looks like

<script type= "text/javascript">
function handleSelection(id) {
    <%=  
    remote_function :url => render_exam_exams_path,:with => "'id='+id" 
    %>
}
</script>

now the the method i was just testing as follows

def render_exam
    @exams = Exam.find(params[:id])
    #either
    #redirect_to home_index_path
    #or open this in new browser tab        
    #render :action => "render_exam"
end

and I have a view called render_exam as well. Now i have checked the server logs and all, everything works fine even the render_exam is generated as i could see that in chrome developer plugin. Now the problem is i want either

  1. the controller action render_exam to open up a new tab and render render_exam view as it seems to be happening remotely (generating render_exam view and all)without changing the jqgrid page. But I couldn't find a way to open up a new browser tab to render the render_exam action view from the render_exam action itself rather than happening behind the scene. or
  2. have the jqGrid (or index view) page redirected to the render_exam view. Now the problem here was the redirect_to action doesn't work in the view as it is supposed to be controller method. So i can't say.

<script type= "text/javascript">
function handleSelection(id) {
    <%= redirect_to :action => render_exam_exams_path, :with => "'id='+id"  %>
}
</script>

otherwise the problem would have been solved. Any help is appreciated thanks

Upvotes: 1

Views: 5157

Answers (1)

Zepplock
Zepplock

Reputation: 29135

First, you can't redirect and render in the same action since there's only one response per action. Second opening a new tab is a client side feature (controlled by your browser), you need to use something like ""target=_blank in your link which will open a new browser which in turn will request a page (render_exam_exams_path in your case) from the server.

Upvotes: 1

Related Questions