提问人:Paul Pettengill 提问时间:1/14/2012 更新时间:1/14/2012 访问量:424
在 Rails 3.1 中通过选择 collection-select 下拉列表进行导航
Navigation via selection of collection-select dropdown in Rails 3.1
问:
我想执行一个相对简单的任务,即从下拉菜单中选择一个值,然后导航到所选项目。(我知道我一定比需要的要困难得多,但这就是我所拥有的)。
schools_controllers.rb
# GET /schools/1
# GET /schools/1.json
def show
@schools = School.order(:name)
@school = School.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @school }
format.css
format.js
end
end
view/schools/show.html.haml
%div.nav
= collection_select(:school, :id, @schools, :id, :name)
assets/javascripts/schools.js.coffee
jQuery ->
$('select#school_id').change ->
alert this.id
我似乎只能访问css标记的id,而不是学校的id。理想情况下,我想使用以下变体导航到该学校:
schools_path[selected_school.id]
任何帮助将不胜感激。
答: 暂无答案
评论