我的控制器:將數據傳遞給JavaScript的
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
正如你看到的上面,我有一個check_teachers
方法,這裏面我得到了老師對象的列表。每個Teacher
對象具有name
和title
屬性。
一個按鈕點擊視圖將觸發check_teachers
方法被調用:
我想顯示所有教師name
和title
在燈箱廣告。我想我需要javascript來實現這一點。但我不知道我可以通過所有教師的數據,從Rails的到的JavaScript,並顯示在實施燈箱一個js數據...
任何人都可以提供這方面的幫助?