简体   繁体   中英

Rails route path

So i'm trying to set up a basic client assignment system, but I'm running into an issue.

These are the paths I want:

assign POST /assign
unassign DELETE /unassign/:id

but I am getting the following from rake routes :

assign POST /assign
       DELETE /unassign/:id

The interesting thing is, when I output my link, the URL looks like this:

http://localhost:3000/assign.1

Why isn't using a / ? Furthermore, how do I make it unassign DELETE /unassign/:id ?


routes.rb

post   '/assign'      , to: 'clients#assign_to'
delete '/unassign/:id', to: 'clients#unassign'

relevent haml

= link_to assign_path(client.id), method: :delete, title: 'Unassign' do
  %img{src: '/assets/unassign.png'}

I want to use unassign_path , not assign_path .. What am I doing wrong?

尝试以下方法:

delete '/unassign/:id', to: 'clients#unassign', as: :unassign

Add the following lines to the beginning of your routes.rb

match   '/assign' => 'clients#assign_to', :via => :post, :as => "assign"
match '/unassign/:id' => 'clients#unassign', :via => :delete, :as => "unassign"

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