简体   繁体   English

Rails路径路径

[英]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 : 但是我从rake routes得到了以下信息:

assign POST /assign
       DELETE /unassign/:id

The interesting thing is, when I output my link, the URL looks like this: 有趣的是,当我输出链接时,URL如下所示:

http://localhost:3000/assign.1

Why isn't using a / ? 为什么不使用/ Furthermore, how do I make it unassign DELETE /unassign/:id ? 此外,如何使它unassign DELETE /unassign/:id


routes.rb 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? 我想使用unassign_path ,而不是assign_path ..我在做什么错?

尝试以下方法:

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

Add the following lines to the beginning of your routes.rb routes.rb添加到routes.rb的开头

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

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

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