2013-02-04 1 views
0

나는 Michael Hartl의 귀중한 튜토리얼을 살펴보고 일부 Rspec 오류가 발생했습니다. 나는 모든 것을 두 번 점검했지만 아직 뭔가 빠져있는 것처럼 보입니다. 오류 메시지는 다음과 같습니다. 내가 모델을 생성하기 전에 생성 명령을 취소 할 실수로 옵션 그래서 레일 모델 Microposts을 파괴 않았다 중 하나에 오타가 만든 Microposts 모델을 생성 할 때 가장 나를 괴롭 히고Rails Rspec 오류 "정의되지 않은 방법"(railsturoial 10 장)

error

건입니다 다시. 그 오류가 내가 보는 오류와 관련이 있는지 궁금합니다.

정말이 자습서를 끝내고 싶습니다. 그래서 제 웹 응용 프로그램을 만들 수 있습니다. 어떤 도움을 주시면 감사하겠습니다.

내 코드는 다음과 같습니다.

micropost_pages_spec.rb

require 'spec_helper' 

describe "MicropostPages" do 
    subject {page} 
    let(:user) {FactoryGirl.create(:user)} 
     before {sign_in user} 
     describe "micropost creation" do 
      before {visit root_path} 

      describe "with invalid information" do 
       it "should not create a micropost" do 
       expect {click_button "Post"}.not_to change(Micropost, :count)    
      end 

      describe "error messages" do 
       before {click_button "Post"} 
       it {should have_content('error')} 
      end 
     end 
    end 
end 

microposts_controller.rb

class MicropostsController < ApplicationController 
    before_filter :signed_in_user, only: [:create, :destroy] 

    def create 
     @micropost = current_user.micropost.build(params[:micropost]) 
     if @micropost.save 
      flash[:success] = "Micropost created!" 
      redirect_to root_path 
     else 
      render 'static_pages/home' 
     end 
    end 

    def destroy 
    end 
end 

static_pages_controller.rb

class StaticPagesController < ApplicationController 
    def home 
    @micropost = current_user.microposts.build if signed_in? 
    end 

    def help 
    end 

    def about 
    end 

    def contact 
    end 

end 

@micropost = current_user.micropost.build(params[:micropost]) 

그것은해야한다 :

@micropost = current_user.microposts.build(params[:micropost]) 

당신이 때 당신이해야 micropost을 사용하고

user.rb (사용자 모델)

class User < ActiveRecord::Base 
    attr_accessible :email, :name, :password, :password_confirmation 
    has_secure_password 
    has_many :microposts, dependent: :destroy 

    before_save {self.email.downcase!} 
    before_save :create_remember_token 

    VALID_EMAIL_REGEX = /\A[\w+\-.][email protected][a-z\d\-.]+\.[a-z]+\z/i 
    validates :name, presence: true, length: {maximum: 50} 
    validates :email, presence: true, format: {with: VALID_EMAIL_REGEX}, 
        uniqueness: {case_sensitive: false} 
    validates :password, presence: true, length: {minimum: 6} 
    validates :password_confirmation, presence: true 

    private 

    def create_remember_token 
     self.remember_token = SecureRandom.urlsafe_base64 
    end 
end 

답변

1

오류는이 라인이다 microposts을 사용하십시오.

+0

하하 와우 감사합니다. 타이머가 끝나면 대답으로 설정됩니다. – jeebface

+0

@jkface : 아직 타이머가 다 되었습니까? –

+1

하하는 남자가 먹어야한다 : D – jeebface

관련 문제