[英]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.