新手问题 如何写一个页面可以向 show 那样接受参数,路由中该怎么写?

dccmmtop · July 27, 2017 · Last by dccmmtop replied at July 27, 2017 · 1186 hits

如何写一个页面可以向 show 那样接受参数,路由中该怎么写?

通常带个冒号就可以的:/control/play/:some/

我试试

3 Floor has deleted
Reply to chenge
resources :nodes do
      collection do
        get :time_more
        get :circle_more
        get :search_list
        get :details_one
        get :details_two
        get :circle_details
        get :circle_three
        get :find_circle
        get :foucs/:name/
      end
    end

这样语法错误吧

我的 foucs.html.erb 和 show.html.erb 功能类似

Reply to dccmmtop

单个写是可以的。你那个写法我不清楚,要实验。

Reply to chenge
get "foucs/:id",to: "nodes#foucs"

我写成这样了,可以的

Reply to didmehh

能具体一点吗?

  • 如果只是用 ID 作为路由参数,你可以试试member.参考 Rails guide

  • 如果是想自定义路由参数,可以试试这个param

resources :notes, param: :identifier

Ps: 其实我看错了,用member不也挺好麽。

另外多个collection可以写在一起:

resources :notes do
 collection do
   get :get :time_more, :circle_more
 end
end

恩恩,谢谢了

dccmmtop closed this topic. 17 Aug 09:11
You need to Sign in before reply, if you don't have an account, please Sign up first.