2012-05-06 5 views
0

私はhttp://ruby.railstutorial.org/chapters/user-microposts#code:sample_micropostsチュートリアルを使用してMicropostモデルを構築しています。マイクロポストオブジェクトがcontentおよびuser_id属性に応答することを確認するためにテストを実行しています。このエラーが発生します。 未定義のメソッド 'password =' for#以下は "User.rb" & "Micropost spec.rb"のコードブロックです。未定義のメソッド 'password =' for#<User:0xb88ac38>

**User.rb** 

    class User < ActiveRecord::Base 
    has_many :arts 
    belongs_to :account 
    attr_accessible :name, :email,:password, :password_confirmation 

     has_many :microposts, dependent: :destroy 
    has_many :relationships, foreign_key: "follower_id", dependent: :destroy 
     has_many :followed_users, through: :relationships, source: :followed 
    has_many :reverse_relationships, foreign_key: "followed_id", 
            class_name: "Relationship", 
            dependent: :destroy 
     has_many :followers, through: :reverse_relationships, source: :follower 

    def following?(other_user) 
    relationships.find_by_followed_id(other_user.id) 
    end 

     def follow!(other_user) 
    relationships.create!(followed_id: other_user.id) 
    end 

    def unfollow!(other_user) 
     relationships.find_by_followed_id(other_user.id).destroy 
    end 
     def accountName 
     account.name 

* Micropost_spec *

'spec_helper'

describe Micropost do 

    let(:user) { FactoryGirl.create(:user) } 
    before do 
    # This code is wrong! 
    @micropost = Micropost.new(content: "Lorem ipsum", user_id: user.id) 
    end 

    subject { @micropost } 

    it { should respond_to(:content) } 
    it { should respond_to(:user) } 

end 

移行ユーザー<のActiveRecord ::移行がデフを変更

クラスCreateUsersが必要ですcreate_table:ユーザーは| t | t.string:カテゴリ

t.timestamps 
end end end 

ユーザーモデル

クラスのユーザー<はActiveRecord ::ベースにhas_many: t.stringに名前を付けるアカウント
has_secure_password attr_accessible:belongs_toの芸術:名前:メールアドレス has_many:マイクロポスト

before_create { generate_token(:auth_token)} 
    has_many :microposts, dependent: :destroy has_many :relationships, foreign_key: "follower_id", dependent: :destroy 
    has_many :followed_users, through: :relationships, source: :followed has_many :reverse_relationships, foreign_key: 

"followed_id"、 CLASS_NAME: "関係"、 依存: にhas_manyを破壊:信者、スルー:reverse_relationships、ソース:フォロワ

はDEF(列)generate_token が 自己[カラムを始めます] = SecureRandom.urlsafe_base64 終了User.exists?(列=>自己[コラム])

def following?(other_user) 
relationships.find_by_followed_id(other_user.id) end 

デフをフォローしよう。(other_user)ながら、 210 relationships.create(followed_id:other_user.id)! はデフフォローし終わり(other_user) relationships.find_by_followed_id(other_user.id).destroyエンドデフACCOUNTNAMEのaccount.name エンドエンドエンド

+0

「has_secure_password」は何を指していますか? – pduersteler

答えて

0

だけの推測!あなたはパスワードの部分を紛失しているように思われるが、http://ruby.railstutorial.org/chapters/modeling-users#sec:adding_a_secure_passwordを見ると、

これが当てはまらない場合は、完全なモデル(カットされているように見えます)とユーザーの移行ファイルを投稿する必要があります。

+0

返信いただきありがとうございます。上記のユーザーのマイグレーションファイルを入れました。あなたがモデルと言うとき、マイクロポストまたはユーザーモデルですか? – Jide

+0

あなたのユーザはパスワードで認証する必要があるので、ユーザモデル – pduersteler

+0

私は上記のユーザモデルを挿入しました – Jide

関連する問題