简体   繁体   中英

ruby on rails Match a url to a controller action

I need to match this link /links/128/dev?usrA=mike&usrB=carl with my controller.

I tried using:

match 'links/:id/dev?usrA=:curr&usrB=:prev', to: 'links#index', via: :get

But it does not work.

Is there any way to match this URL with my controller?

I generally avoid match and prefer the more explicit get (if you will only allow a GET )

get 'links/:id/dev', to: 'links#index'

You do not have to specify the parameters, these are parsed automatically.

match '/links/:id/dev', to: 'links#index', via: :get

Will work fine. Everything after the "?" are considered parameters and are not considered when matching the URL.

match 'links/:id/dev', to: 'links#index', via: :get

You don't need to be explicit while sending a GET request. You can send whatever you want in the GET request, and can receive in the method through the params .

match '/links/:id/dev' => 'controller#action', :via => [:get], :as => :get_links

然后,您可以使用javascript中的get_links_path()进行访问

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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