通过 Rails 3.1 中的集合选择下拉菜单进行导航

发布于 2024-12-26 17:22:29 字数 802 浏览 1 评论 0原文

我想执行一个相对简单的任务,从下拉菜单中选择一个值,然后导航到所选项目。 (我知道我一定让这件事变得比需要的困难得多,但这就是我所拥有的)。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文