undefined method `model_name' for Project:Class

ruby, ruby-on-rails

Solution

if Project is not an active record subclass, you need these and you can use `form_for`

class Project
  extend ActiveModel::Naming
  include ActiveModel::Conversion
  def persisted?
    false
  end
  ...
end

view:

<%= form_for(@newproject)  do |f| %>
  <%= f.label :name %>:
  <%= f.text_field :description %><br />
<% end %>

Problem

I've looked through all the related questions but nothing's new for me here. I have a Project controller with "new" action ``` class ProjectsController < ApplicationController def new @newproject = Project.new end end ``` Project is a simple class, not active record: ``` class Project attr_accessor :name, :description def initialize @name = "" @description = "" end end ``` I get the error "undefined method `model_name' for Project:Class" This is an erb file sample: ``` <%= form_tag(@newproject) do |f| %> <%= f.label :name %>: <%= f.text_field :description %><br /> <% end %> ```

Original source