有点困惑为什么这不起作用。我在 Windows 7 上使用 Ruby 1.9.2 和 Rails 3.0.3。
但是,尝试为 post 模型制作带有formtastic 的表单时,当我尝试渲染视图时,我不断收到NilClass:Class 的未定义方法“model_name” 。
相关代码:
恶魔控制器.rb
class DemonlyController < ApplicationController
def index
@post = Post.all
end
end
Posts_controller.rb
class PostsController < ApplicationController
end
Post.rb
class Post < ActiveRecord::Base
attr_accessible :title, :post, :date, :time, :user, :visible, :comments
end
索引.html.erb
<h1>Demonly</h1>
<% semantic_form_for @post do |f|%>
<%= f.errors %>
<%= f.inputs do %>
<%= f.input :title %>
<%= f.input :post %>
<%= f.input :date %>
<%= f.input :time %>
<%= f.input :user %>
<%= f.input :visible %>
<%= f.input :comments %>
<% end %>
<% end %>
很可能我正在做一些非常愚蠢的事情,因为我生病了,精神混乱。
提取的源代码(在第 2 行附近):
- <% semantic_form_for @post do |f|%>
- <%= f.errors %>
- <%= f.inputs 做 %>
- <%= f.input :title %>
让我知道是否需要其他任何东西。
编辑:忘记改回一些东西。
忘记包含 db 架构:
create_table "posts", :force => true do |t|
t.string "title"
t.text "post"
t.datetime "date"
t.datetime "time"
t.string "user"
t.boolean "visible"
t.boolean "comments"
t.datetime "created_at"
t.datetime "updated_at"
end