简体   繁体   English

非常基本的轨道的link_to问题

[英]Very basic rails link_to issue

Hello all I have a Delete link that I'm trying to create with the following code: 大家好,我有一个要使用以下代码创建的Delete链接:

 <%= link_to 'Delete', element, method: :delete, data: { confirm: 'Are you sure?' } %>

However the resulting link is /element.id where the id is the integer id. 但是,结果链接为/element.id,其中id是整数id。 How would I change that . 我该如何改变呢。 to a / sorry I know this is very elementary but I couldn't find any documentation on it. / /对不起,我知道这很基础,但是我找不到任何文档。

我猜问题出在config/routes.rb ,它应该包含对element的引用,例如:

resources :element

Try this 尝试这个

 <%= link_to 'Delete', destroy_modelname_path(element), method: :delete, data: { confirm: 'Are you sure?' } %>

Replace modelname with the name of your model. 用模型名称替换modelname

Run rake routes in terminal in your app to see all routes. 在应用程序的终端中运行rake routes ,以查看所有路径。

There is something wrong with routes file. 路由文件有问题。 It seems that your routing routine writes id in the place of :format. 您的路由例程似乎在:format位置写了id。

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

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