Question

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?

Était-ce utile?

La solution

Try this instead:

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

Autres conseils

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"
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top