Rails,为什么link_to始终使用方法[GET],即使我已经指定方法[post]或[delete]
我已经看到其他一些人也问了这个问题,但是我发现没有人得到一个令人满意的答案。
为什么rails link_to
始终使用方法:get
,即使应用了其他一些方法,但是当您将link_to
更改为button_to
它开始工作吗?
以以下行:以下行: <%= link_to“登录”,destroy_user_session_path,方法:: delete,class:“ link”%>
vs <%= button_to“登录”,destroy_user_session_path,方法:: delete,class,class:“ link”%>
所有轨道文档告诉我method
应该工作。我什至从那里复制了代码示例并进行了编辑以适合我的代码,但它仍然不起作用。尽管Button_to是一个足够的解决方法,但我的一半链接是链接,而其他半按钮则伪装成链接是很烦人的。
我正在使用Rails 7。
谢谢。
I have seen a few other people also ask this question, but no one that I have found has been given a satisfactory answer.
Why is it that rails link_to
always uses method :get
, even though some other method has been applied, but the moment you change the link_to
to button_to
it starts working?
Take, for example, the following line:<%= link_to "Log out", destroy_user_session_path, method: :delete, class:"link"%>
vs<%= button_to "Log out", destroy_user_session_path, method: :delete, class:"link"%>
All of rails documentation tell me that method: :post
should work. I have even copied code examples from there and edited it to suit my code, and it still doesn't work. While button_to is an adequate workaround, it is annoying to have half of my links being links, and the other half buttons disguised as links.
I am using rails 7.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更新:进一步谷歌搜索,我发现了这一点: https://github.com/rails/rails/rails/rails/rails/rails/rails/issues/issues/issues/issues/issues/issues /44185 ,有一个对我有用的解决方案。
基本上,
方法
被弃用,而新方法是使用。如果这不起作用,请尝试
先运行命令。
至少对我有用。
UPDATE: Googling further, I found this: https://github.com/rails/rails/issues/44185, which had a solution that worked for me.
Basically,
method
is deprecated, and the new way is to useinstead. If this doesn't work, try running the commands
first.
It worked for me, at least.