简体   繁体   English

带有参数的Rails自定义路线

[英]Rails custom route with params

I have a bunch of generated links created by 我有一堆由创建的链接

  <% @location.exits.each do |e| %>
    <%= link_to e.name, go_to_path(e) %><br/>
  <% end %>

which goes to: get 'go_to' => 'adventure#goto' in routes.rb 转到:在routes.rb get 'go_to' => 'adventure#goto'

which links back to: 链接回:

  def goto
    current_user.location_id = params[:id]
    render 'index'
  end

However, when clicking on any of the links, it leads me to the url: http://localhost:3000/go_to.2 instead of say http://localhost:3000/go_to/2 但是,单击任何链接时,它将带我到URL: http://localhost:3000/go_to.2而不是http://localhost:3000/go_to.2 http://localhost:3000/go_to/2

Not sure what I'm doing wrong here or how to fix it. 不知道我在这里做错了什么或如何解决。

修正您的路线:

get 'go_to/:id' => 'adventure#goto'

Read about routes in Rails and the-query-string

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM