1

I am developoing a Rails v2.3.2 app. A very basic Rails structure implemented as below:

I have a controller:

class SchoolController < ApplicationController
  ...

  def check_teachers
    @school = School.find params[:id]
    @teachers = @school.teachers
  end

end

my route definition in route.rb:

map.check_teachers, '/school/check_teachers/:id' :controller => :school, :action => :check_teachers

A link click will trigger the view:

link_to 'Check teachers', check_teachers_path(:id => @school.id)

check_teachers's view check_teachers.html.erb:

<div>
Hello 
<%= render :partial => 'show_teachers'%>
</div>

I would like the link click to show the above view as a jQuery-UI dialog instead of a page view. How to achieve this??

----Update-----

Please check also my comment on @plaes 's answer.

Mellon
  • 37,586
  • 78
  • 186
  • 264

2 Answers2

2

You are missing the jQuery UI code to set up the dialog in check_teachers.html.erb:

<script>
$(function() {
  $('#dialog').dialog();
});
</script>
<div id='dialog'>
Hello 
<%= render :partial => 'show_teachers'%>
</div>

Also, you need to include the required jQuery dependencies (jQuery and jQuery-UI). This is left as an exercise...

plaes
  • 31,788
  • 11
  • 91
  • 89
  • I forget to mention I have all the required js libraries set up. So, that is not in consideration in my case. I actually tried your way before I post, since I have the route.rb configuration, the link click will always render an new empty page then the popup dialog is on top of the empty page, but I want it to show on the previous original page. – Mellon Dec 13 '11 at 09:05
  • OK, then you need to load your dialog with the AJAX request. – plaes Dec 13 '11 at 09:23
  • 1
    See this question: http://stackoverflow.com/questions/809035/ajax-jquery-ui-dialog-window-loaded-within-ajax-style-jquery-ui-tabs – plaes Dec 13 '11 at 09:27
1

By default, it renders an html page. Just before closing the controller add this code

respond_to do |format|
  format.js {}
end

Rename your view to check_teachers.js.erb Inside this file, include your necessary jquery.

rdsoze
  • 1,768
  • 1
  • 15
  • 25