Reputation: 2149
I'm getting the following error while trying to create a form, undefined method 'model_name' for NilClass:Class
This project of mine is to capture my ideas. I could use a google doc but figured this should be easy enough to try and code an app for myself. Below is the code as I think it should be from what I read on the simple form site in my newopp.html.erb (in my opps view folder.
I created a controller and a model and I am certain part of my problem is the fact that I can't figure out what I need to code or what to add for code to properly complete this step. All the tutorials I have looked at gave me a couple ideas to play with and try to make work to no avail.
So basically I am sitting on a rails generated controller named opps_controller.rb and a model called opp.rb. Both of these are nothing more than what the generator provided since I had to go back to square one
Simple form code that I have started with
<%= simple_form_for @opp do |f| %>
<%= f.input :title %>
<%= f.input :subtitle %>
<%= f.input :description %>
<%= f.input :idea %>
<%= f.input :added %>
<%= f.button :submit %>
<% end %>
opp.rb file
class Opp < ActiveRecord::Base
attr_accessible :added, :description, :idea, :subtitle, :title
end
If it makes a difference, I have migrated the database, I ran the simple form install script with the bootstrap configuration. I'm using rails 3.2.9
and ruby 1.9.3p362
(2012-12-25 revision 38607) [x86_64-darwin12.2.1]
As I mentioned I just have a blank controller that was created using a generator and I need to get the CRUD functionality working. Everything I have tried has failed at this point. I appreciate any assistance you can provide.
Upvotes: 0
Views: 57
Reputation: 4880
It shouldn't be newopp.html.erb
, just new.html.erb
. So the path would be /views/opps/new.html.erb
If you're still getting an error then make sure @opp
is defined in the controller:
class OppsController < ApplicationController
def new
@opp = Opp.new
end
def create
@opp = Opp.new
if @opp.update_attributes(params[:opp])
...
else
render 'new'
end
end
end
Upvotes: 1