Link_to Rails 导致路由错误
所以我有一个简单的模型歌曲,以标题和喜欢作为属性。
我将其以表格形式显示在歌曲索引页面上。我想在点击链接时增加喜欢的数量。
我目前的观点是:
<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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
包装您的
:action
参数,以确保路由器意识到:remote
参数不是您路径的一部分:Wrap your
:action
argument to make sure the router realizes the:remote
argument is not part of your path:这是我在遇到同样问题时发现的一个很好的答案。
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.