简体   繁体   English

Ruby on Rails + FriendlyId gem + Acts_as_Votable gem-收到Heroku错误

[英]Ruby-on-Rails + FriendlyId gem + Acts_as_Votable gem - getting a Heroku error

In my index page I have the following as part of setting up the Acts_as_votable gem. 在我的索引页中,以下是设置Acts_as_votable gem的一部分。

<%= link_to like_bike_path(bike), method: :put, class: "btn btn-default" do %>

It was working fine until I added FriendlyId, probably because the like_bike_path is looking for an id not a friendlyID (ie vanity URL). 在我添加FriendlyId之前,它一直运行良好,可能是因为like_bike_path在寻找的是id,而不是friendlyID(即虚荣网址)。 Is there a way to change 有没有办法改变

like_bike_path

to something like

like_friendly.find_path

Works on Localhost:3000 but Heroku logs tell me ActionView::Template::Error (undefined method slug' for #<Bike" for my two acts_as_votable calls "like_bike_path(bike)" and "<%= bike.get_upvotes.size %>". 在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" ”。

thanks! 谢谢!

#app/models/bike.rb
class Bike < ActiveRecord::Base
   extend FriendlyId
   friendly_id :column, use: [:finders, :slugged]
end

This will allow use of the slug without having to change the default pattern in ActiveRecord... ( @bike = Bike.find params[:id] ). 这将允许使用的slug ,而无需改变在ActiveRecord的默认图案...( @bike = Bike.find params[:id]

-- -

In regards your heroku error, it means you have not got the database migrated (it doesn't include slug in its columns). 关于您的heroku错误,这意味着您尚未迁移数据库(在其列中不包含slug )。

You need to make sure you run heroku run rake db:migrate , as well as ensuring that you've re-saved any @bike records (so the slug column is populated). 你需要确保你运行heroku run rake db:migrate ,并确保你已经重新保存任何@bike记录(所以slug柱填充)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM