我关注guide.ruby.org,但有些错误我不知道如何解决。
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>
但是我得到了错误,当我从指南步入一步时,一切都好,这是错误信息:
有什么不对吗?谢谢回答我。未定义的方法`comemnts&#39;对于#
答案 0 :(得分:2)
这是一个简单的拼写错误,我可以看到。
@list.comemnts.build
应该是
@list.comments.build
答案 1 :(得分:2)
视图中有拼写错误 - 应该是
@list.comments.build
不是
@list.comemnts.build