ERROR: undefined method `comemnts' for
ERROR: undefined method `comemnts' for
我按照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>
但是我遇到了错误,当我从指南中一步步进行时,一切正常,这是错误信息:
undefined method `comemnts' for #
有什么问题吗?谢谢回答我。
据我所知,这是一个简单的拼写错误。
@list.comemnts.build
应该是
@list.comments.build
视图中有错字 - 应该是
@list.comments.build
不是
@list.comemnts.build
我按照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>
但是我遇到了错误,当我从指南中一步步进行时,一切正常,这是错误信息:
undefined method `comemnts' for #
有什么问题吗?谢谢回答我。
据我所知,这是一个简单的拼写错误。
@list.comemnts.build
应该是
@list.comments.build
视图中有错字 - 应该是
@list.comments.build
不是
@list.comemnts.build