Ale*_*ait 3 ruby ruby-on-rails-3
我是Rails 3的新手,我已经按照一些教程进行操作,现在我正在尝试使用创建的代码"玩".我已经按照http://guides.rubyonrails.org/getting_started.html上的教程进行了操作
我正在尝试使用以下代码在主页上呈现新帖子的表单:
<%= render :partial => "posts/form" %>
Run Code Online (Sandbox Code Playgroud)
帖子/ _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 %>
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
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'
Run Code Online (Sandbox Code Playgroud)
我明白这对你们中的一些人来说似乎是件小事,但我正在努力了解Rails上的一切是如何运作的,所以我希望你能理解我.
提前致谢 !
| 归档时间: |
|
| 查看次数: |
4255 次 |
| 最近记录: |