Undefined method `` model_name '' for NilClass: class (using formtastic in Rails 3.0.3, Ruby 1.9.2)

Somewhat confused why this does not work. I am using Ruby 1.9.2 with Rails 3.0.3 on Windows 7.

Trying to make a form with formtastic for the post model, however, I continue to get the undefined `model_name 'method for NilClass: Class when trying to display 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 %>

Most likely, I am doing something very stupid, seeing that I am sick and mentally clothed.

Extracted source (around line # 2):

  • <% semantic_form_for @post do | f |%>
  • <% = f.errors%>
  • <% = f.inputs do%>
  • <% = f.input: title%>

Let me know if something else is needed.

: .

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
+3
1

Erm, :

  • , .
  • PostsController @post = Post.all
  • @posts,
+8

Source: https://habr.com/ru/post/1786152/


All Articles