[英]Ruby-on-Rails + FriendlyId gem + Acts_as_Votable gem - getting a Heroku error
在我的索引页中,以下是设置Acts_as_votable gem的一部分。
<%= link_to like_bike_path(bike), method: :put, class: "btn btn-default" do %>
在我添加FriendlyId之前,它一直运行良好,可能是因为like_bike_path在寻找的是id,而不是friendlyID(即虚荣网址)。 有没有办法改变
like_bike_path
像
like_friendly.find_path
在Localhost:3000上运行,但是Heroku日志告诉我ActionView::Template::Error (undefined method slug' for #<Bike"
对于我的两个act_as_votable调用“ like_bike_path(bike)”和“ <%= bike.get_upvotes.size%>, ActionView::Template::Error (undefined method slug' for #<Bike"
slug'for ActionView::Template::Error (undefined method slug' for #<Bike"
”。
谢谢!
#app/models/bike.rb
class Bike < ActiveRecord::Base
extend FriendlyId
friendly_id :column, use: [:finders, :slugged]
end
这将允许使用的slug
,而无需改变在ActiveRecord的默认图案...( @bike = Bike.find params[:id]
-
关于您的heroku
错误,这意味着您尚未迁移数据库(在其列中不包含slug
)。
你需要确保你运行heroku run rake db:migrate
,并确保你已经重新保存任何@bike
记录(所以slug
柱填充)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.