我完全按照寶石的說明 - https://github.com/jaustinhughey/vanities - 以及其他一切正常。虛榮寶石在我的用戶模型上拋出一個錯誤
但是,當我試圖加載我的主頁,我收到此錯誤:
NameError in HomeController#index
undefined local variable or method `has_vanity' for #<Class:0x000001015691e8>
app/models/user.rb:2:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/controllers/home_controller.rb:3:in `index'
這是我User.rb
class User < ActiveRecord::Base
has_vanity
has_many :feedbacks_as_poster, :foreign_key => :poster_id, :class_name => 'Feedback'
has_many :feedbacks_as_receiver, :foreign_key => :receiver_id, :class_name => 'Feedback'
end
# == Schema Information
#
# Table name: users
#
# id :integer not null, primary key
# email :string(255)
# f_name :string(255)
# l_name :string(255)
# username :string(255)
# role_id :integer
# picture :string(255)
# about_me :string(255)
# website :string(255)
# created_at :datetime
# updated_at :datetime
#
這裏是我的Home Controller
class HomeController < ApplicationController
def index
@users = User.all
@feedback = Feedback.new
end
end
思考?
編輯1:看我下面Gemfile
:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'execjs'
gem 'therubyracer'
gem 'vanities'
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
gem 'jquery-rails'
group :development do
gem 'sqlite3'
gem 'annotate', :git => 'git://github.com/ctran/annotate_models.git'
end
group :test do
gem 'turn', :require => false
end
group :production do
gem 'pg', :require => 'pg'
end
編輯2:如果我去我創建了一個用戶的URL輪廓,例如localhost:3000/test
我看到下面的錯誤,這導致我相信寶石的一部分正在工作,因爲它實際上提取了正確的記錄。但是別的東西被打破了。
Started GET "/test" for 127.0.0.1 at 2011-09-07 20:00:19 -0500
Processing by VanitiesController#show as HTML
Parameters: {"vname"=>"test"}
Vanity Load (0.2ms) SELECT "vanities".* FROM "vanities" WHERE "vanities"."name" = 'test' LIMIT 1
Completed 500 Internal Server Error in 100ms
NameError (undefined local variable or method `has_vanity' for #<Class:0x0000010313d478>):
app/models/user.rb:2:in `<class:User>'
app/models/user.rb:1:in `<top (required)>'
app/controllers/vanities_controller.rb:8:in `show'
你能否證實它在你的Gemfile,你已經運行'束install'? –
@ Jesse-Wolgamott我已經完成了這兩件事,我甚至用我的Gemfile更新了這個問題。 – marcamillion
我想知道如果虛榮表有一些不規則的條目。你能清除它,還是驗證它只有你所期望的? –