我正在阅读Hartl的Rails教程,并在第10章中陷入了相当令人沮丧的境地。
<%= form_for(@micropost) do |f| %>
<%= render 'shared/error_messages', object: f.object %>
<div class="field">
<%= f.text_area :content, placeholder: "Compose new micropost..." %>
</div>
<%= f.submit "Post", class: "btn btn-large btn-primary" %>
<% end %>
使用此会产生此错误
ActionView::Template::Error:
undefined local variable or method `object' for #<#<Class:0x00000106cad990>:0x00000103395f18>
我已经经历了几次,我正在努力想知道我哪里出错了。我已经提到其他SO帖子,但到目前为止还没有提供任何解决方案。
这是
_error_messages.html.erb
<% if object.errors.any? %>
<div id="error_explanation">
<div class="alert alert-error">
The form contains <%= pluralize(object.errors.count, "error") %>.
</div>
<ul>
<% object.errors.full_messages.each do |msg| %>
<li>* <%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
controller.rb
class MicropostsController < ApplicationController
before_action :signed_in_user
def create
@micropost = current_user.microposts.build(micropost_params)
if @micropost.save
flash[:success] = "Micropost created!"
redirect_to root_url
else
render 'static_pages/home'
end
end
def destroy
end
private
def micropost_params
params.require(:micropost).permit(:content)
end
end
家庭控制器
def home
@micropost = current_user.microposts.build if signed_in?
end
如果我正在通过&#39;对象&#39;作为通过部分论证它应该工作不?
由于