1

My controller:

class SchoolController < ApplicationController

  def index
    ...
  end

  def edit
    @school=School.find_by_id params[:id]

  end

  def check_teachers
    @teachers = @school.teachers

    #How to show teachers' names and titles in a lightbox by javascript ?

  end

end

As you see above, I have a check_teachers method, inside which I got a list of teachers objects. Each Teacher object has name and title attributes.

A button click on the view will trigger the check_teachers method get called:

I would like to show all teachers name and title in a lightbox. I think I would need javascript to implement this. But I don't know how can I pass all the teachers' data from Rails to javascript and show the data in a js implemented lightbox...

Anyone can provide any help on this?

1 Answer 1

1

you can do it with ajax. Simpliest way is to use FancyBox(jquery plugin, http://fancybox.net/home )

your button code should looks like

<a id="ajax_button" href="<%= url_for :controller => :school, :action =>:check_teachers, :id=>@school.id %>">Check teachers</a>

then add this javascript

$(document).bind('load', function() { $("#various3").fancybox({ajax:{type : "GET" } })

and your method controller action should looks like

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

but it's better to move @school = School.find(params[:id]) to before_filter

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.