通过 Rails 3.1 中的集合选择下拉菜单进行导航
我想执行一个相对简单的任务,从下拉菜单中选择一个值,然后导航到所选项目。 (我知道我一定让这件事变得比需要的困难得多,但这就是我所拥有的)。
school_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]
任何帮助将不胜感激。
I'd like to perform a relatively simple task of selecting a value from a dropdown menu, and then navigate to the selected item. (I know I must be making this much harder than it needs to be, but here is what I have).
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
All I can seem to access is the id of the css marker, not the id of the school. Ideally, I'd like to navigate to that school using some variation of:
schools_path[selected_school.id]
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论