Reputation: 300
A tad bit confused as to why this isn't working. I'm using Ruby 1.9.2 with Rails 3.0.3 on Windows 7.
Trying to make a form with formtastic for a post model, however, I keep getting undefined method `model_name' for NilClass:Class when I try to render the view.
Relevant code:
Demonly_controller.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
Index.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 %>
It's rather likely that I'm doing something very stupid seeing as I'm sick and mentally cloudy.
Extracted source (around line #2):
Let me know if anything else is needed.
EDIT: Forgot to change some things back.
Forgot to include the db schema:
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
Upvotes: 3
Views: 26747
Reputation: 17408
Erm, several problems:
@post = Post.all
outside of a method context@posts
referenced in your viewUpvotes: 8