0

에 대한 오류를 던지고 있습니다. 보석에 대한 지침을 완벽하게 따라했습니다 (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 :

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 : 내 아래 Gemfile를 참조 나는 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' 
+0

은 당신이 당신의 Gemfile에있어 확인할 수 있습니다 당신은'번들 install '이다 실행했습니다 : A와

해결 방법, 당신은 전화로 "has_vanity"대신에 다음 코드를 추가하려고 할 수 있습니다? –

+0

@ Jesse-Wolgamott 나는이 두 가지를 다했는데, 나는 또한 내 Gemfile로 질문을 업데이트했다. – marcamillion

+0

부락 테이블에 불규칙한 항목이 있는지 궁금합니다. 그것을 지우거나 기대 한 바를 가지고 있는지 확인할 수 있습니까? –

답변

1

는 내 말에이 문제를 복제하려고했습니다, 그리고 그것이 가능한 문제의 원인이 될 수있는 응용 프로그램에 고유 한 뭔가 의미가 중복 얻을 수없는 것.

작동 예제로 https://github.com/jaustinhughey/vtest을 참조 할 수 있습니다.

# < 클래스에 대한 정의되지 않은 지역 변수 또는 메소드`has_vanity ' : 0x000001015691e8>

즉 "사용자"하지 않을 경우,하지 "

은 내가 당신의 문제에 대한 흥미있는 것은 이것이다 수업"? 허영심은 객체에 대한 다형성 연관성과 사용 가능한 방법으로 ActiveRecord에 대한 허영심을 밀어 냄으로써 작동합니다. 그런 다음 "has_vanity"라고 부르면 자동으로 해당 다형성 연결을 사용할 수 있습니다. 그것은 거기에 들어가기위한 단순한 방법입니다 - 바로 가기입니다.

귀하의 경우 ActiveRecord와 함께 수행되는 "펑키"가 있는지 궁금합니다. 구체적으로 그 원인을 알 수는 없지만, 어떤 이유로 사용자의 경우에는 메서드가 일반 객체가 존재하지 않습니다.

class User < ActiveRecord::Base 
    has_one :vanity, :as => :vain # instead of 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 
+0

그 일은 아름답게 작동했습니다. 호기심에서'localhost.com/test'로 가면'localhost.com/users/1'로 리디렉션됩니다. 그것은 의도 된 행동 이었습니까, 아니면 다른 사람이 실행중인가요?의도 한 동작 인 경우 URL을 영구 URL (예 :'localhost.com/test')으로 유지하고 그 상태로 유지하려면 어떻게해야합니까? 감사. – marcamillion

+0

예, 의도 한 동작입니다. 그것을 유지/테스트하고 싶다면 vanity_controller.rb를 변경하여 리디렉션을 수행하는 대신 원하는보기를 렌더링 할 수 있습니다. –

+0

아, 흥미 롭습니다 ... 좋아요, 그걸 가지고 놀 것입니다. 감사! – marcamillion