我对Rails 3非常陌生,并且我遵循了一些教程,现在我试图用创建的代码“玩”。我遵循了http://guides.rubyonrails.org/getting_started.htmlRails 3渲染/部分
我正在试图渲染主页上的新帖这个代码的形式教程:
<%= render :partial => "posts/form" %>
的职位/ _form.html.erb看起来是这样的:
<%= form_for(@post) do |f| %>
<% if @post.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @post.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br />
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :title %><br />
<%= f.text_field :title %>
</div>
<div class="field">
<%= f.label :content %><br />
<%= f.text_area :content %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
,这是错误我得到:
undefined method `model_name' for NilClass:Class
Extracted source (around line #1):
1: <%= form_for(@post) do |f| %>
2: <% if @post.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
Trace of template inclusion: app/views/home/index.html.erb
Rails.root: d:/server/cazare
Application Trace | Framework Trace | Full Trace
app/views/posts/_form.html.erb:1:in `_app_views_posts__form_html_erb___794893824_70478136_519766'
app/views/home/index.html.erb:5:in `_app_views_home_index_html_erb__967672939_70487520_0'
我明白,这对于你们中的一些人来说似乎是小菜一碟,但我试图理解Rails上的一切工作原理,所以我希望你能理解我。
在此先感谢!
您是否收到错误或者是什么问题? – Wukerplank 2011-04-07 08:16:00
那段代码(对'model_name'的调用)在你发布的代码中没有任何地方。您需要查看错误,因为它应该为您提供文件名和行号,并发布该代码段,并具体告诉我们发生了什么行。 – 2011-04-07 08:17:31
我更新了错误信息。抱歉没有发布在第一个地方。 – 2011-04-07 08:18:08