Link_to Rails 导致路由错误

发布于 2025-01-06 05:18:55 字数 800 浏览 6 评论 0原文

所以我有一个简单的模型歌曲,以标题和喜欢作为属性。

我将其以表格形式显示在歌曲索引页面上。我想在点击链接时增加喜欢的数量。

我目前的观点是:

 <td> <%= link_to 'LIKE',  :action => "update", :remote => true%> </td>

在我的ongs_controller.rb中我有:

def update
  @song = Song.find(params[:id])                                                                                                                                
  @song.likes +=1

我在单击链接时收到此错误:

No route matches [GET] "/assets"

我知道这是基本的,有人可以帮助我了解这里发生了什么吗?

谢谢

更新!!!!!!!我将以下内容放入我的 application.rb 中 config.assets.enabled = false

但我仍然得到这个:

No route matches {:action=>"update", :remote=>true, :controller=>"songs"}

so I have a simple model songs with title and likes as attributes.

I display it in a table form on the songs index page. I want to increment the number of likes upon clicking a link.

I have this in my view currently :

 <td> <%= link_to 'LIKE',  :action => "update", :remote => true%> </td>

in my songs_controller.rb i have :

def update
  @song = Song.find(params[:id])                                                                                                                                
  @song.likes +=1

I get this error on clicking link:

No route matches [GET] "/assets"

I know this is basic, will someone please help me understand what is going on here?

Thank you

UPDATE!!!!!!! i put this following in my application.rb
config.assets.enabled = false

but I still get this:

No route matches {:action=>"update", :remote=>true, :controller=>"songs"}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉栀 2025-01-13 05:18:55

包装您的 :action 参数,以确保路由器意识到 :remote 参数不是您路径的一部分:

<%= link_to 'LIKE', {:action => "update"}, :remote => true %>

Wrap your :action argument to make sure the router realizes the :remote argument is not part of your path:

<%= link_to 'LIKE', {:action => "update"}, :remote => true %>
横笛休吹塞上声 2025-01-13 05:18:55

这是我在遇到同样问题时发现的一个很好的答案。
Rails 3 如何向控制器添加自定义方法

这篇文章还有一个很好的railscast 链接,它也解释了部分问题。

This is a good answer I found when having trouble with the same thing.
Rails 3 how to add a custom method to controller

This post also has a good link to a railscast which explains part of the problem too.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文