SongsController中的NameError #index uninitialized constant Song :: FriendlyId
所以,我有一个应用程序,用户将进行大量的社交分享。 因此,链接必须看起来很漂亮。
我已经安装了friendly_id gem
但似乎得到了这个错误:
NameError in SongsController#index uninitialized constant Song::FriendlyId class Song < ActiveRecord::Base extend FriendlyId friendly_id :title, use: :slugged
song.rb snippit
class Song < ActiveRecord::Base extend FriendlyId friendly_id :title, use: :slugged
歌曲控制器snippits
class SongsController params[:page], :per_page => 15) get_last_song else @songs = Song.order('id').order('plusminus desc nulls last').paginate(:page => params[:page], :per_page => 15) #@songs = Song.tally.paginate(:page => params[:page], :per_page => 15) get_last_song end end def set_song @song = Song.friendly.find(params[:id]) end def song_params params.require(:song).permit(:title, :artist, :url, :track, :user_id, :tag_list, :query, :genre, :genre_names, ) end end
schema.rb snippits
create_table "songs", force: true do |t| t.string "title" t.string "artist" t.text "url" t.string "track_file_name" t.string "track_content_type" t.integer "track_file_size" t.datetime "track_updated_at" t.integer "user_id" t.datetime "created_at" t.datetime "updated_at" t.integer "plusminus" t.string "slug" end add_index "songs", ["slug"], name: "index_songs_on_slug", unique: true, using: :btree create_table "friendly_id_slugs", force: true do |t| t.string "slug", null: false t.integer "sluggable_id", null: false t.string "sluggable_type", limit: 40 t.string "scope" t.datetime "created_at" end
问题解决了,每当你看到未初始化的常数时,通常意味着你必须运行
bundle install
然后
exit // rails s (restart your server)