2016-04-03 12 views
0

私はguide.ruby.orgに従っていますが、それを解決する方法がわかりません。エラー:未定義のメソッド `comemnts 'の

class List < ActiveRecord::Base 
    has_many :comments, dependent: :destroy 
end 

`

class Comment < ActiveRecord::Base 
    belongs_to :list 
end 

`

class CommentsController < ApplicationController 
    before_action :set_list 

    def index 
    @comments = @list.comments.order('created_at DESC') 
    end 

    def create 
    @comment = @list.comments.create(comment_params) 
    @comment.user_id = current_user.id 

    if @comment.save 
     respond_to do |format| 
      format.html { redirect_to list_path(@list) } 
      format.js 
     end 
    else 
     flash[:alert] = 'Check the comment form, something went wrong.' 
     render root_path 
    end 
    end 

    private 

    def comment_params 
    params.require(:comment).permit(:content) 
    end 

    def set_list 
    @list = List.find(params[:list_id]) 
    end 

end 

`

# gem 'simple_form' 
# gem 'foundation-rails' 
    <div class="comment-form"> 
     <%= simple_form_for [@list, @list.comemnts.build] do |f| %> 
      <%= f.textarea :content, placeholder: 'add comment...', 
           class: "comment_content", 
           id: "comment_content_#{list.id}", 
           data: { list_id: "#{list.id}", 
           value: "#{list.comments.count}" } %> 

      <%=f.button :submit, 'New Comment', class: 'comment-submit-button' %> 
     <% end %> 

    </div> 

しかし、私はエラーを得た私はステップツーステップ時にガイドから、すべてがOKです、ここにバグ情報があります:

undefined method `comemnts' for #

何か間違っていますか?ありがとうございます。

答えて

2

わかりましたが、それは簡単なスペルミスです。

@list.comemnts.build 

@list.comments.build 
+0

はどうもありがとうございましべきです。 – dongdongxiao

2

あなたはビューにタイプミスを持っているべきであるが -

@list.comments.build 

ない

@list.comemnts.build 
+0

ありがとうございました。 – dongdongxiao

関連する問題