私は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 エンドエンドエンド
「has_secure_password」は何を指していますか? – pduersteler