我遵循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>
,但我得到的錯誤,當我一步到臺階的距離指導,一切正常,這裏是錯誤信息:
undefined method `comemnts' for #
有什麼不對嗎?謝謝回答我。
非常感謝你。 – dongdongxiao