title: Ruby on Rails: undefined method `model_name' for NilClass:Class
body: <p>I am trying to allow a user to enter a project into a database. One of the fields allows them to enter multiple technologies for that project.</p>
  
  <p>Here is my project controller, new and create action.</p>
  
  <pre><code>def new
    @project = Project.new
    @all_technols = Technol.all
    @project_technol = @project.projecttechnols.build
  
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @project }
    end
  end
  
  def create
    @project = Project.new(params[:project])
    params[:technols][:id].each do |technol|
      if !technol.empty?
        @project.projecttechnols.build(:technol_id =&gt; technol)
      end
    end
  end
  </code></pre>
  
  <p>Here is my new project view for the multi select technology dropdown.</p>
  
  <pre><code>&lt;%= fields_for(@project_technol) do |ab| %&gt;
    &lt;div class="tech"&gt;
      &lt;%= ab.label "All Tech" %&gt;&lt;br/&gt;
      &lt;%= collection_select(:technols, :id, @all_technols, :id, :tech, {}, {:multiple =&gt; true} ) %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p><strong>project.rb</strong></p>
  
  <pre><code>class Project &lt; ActiveRecord::Base
    attr_accessible :tech
    has_many :projecttechnols
    has_many :technols, :through =&gt; :projecttechnols
  end
  </code></pre>
  
  <p><strong>technol.rb</strong></p>
  
  <pre><code>class Technol &lt; ActiveRecord::Base
    attr_accessible :tech
    has_many :projecttechnols
    has_many :projects, :through =&gt; :projecttechnols
  end
  </code></pre>
  
  <p><strong>projecttechnol.rb</strong></p>
  
  <pre><code>class Projecttechnol &lt; ActiveRecord::Base
    attr_accessible :project_id, :technol_id
    belongs_to :technol
    belongs_to :project
  end
  </code></pre>
  
  <p>At the moment, I have a page where the user can enter a new technology. But I want to move this option to the create new project page, where they can either select existing technologies, or enter a new one, or do both, and they would save with that project.</p>
  
  <p>When I try to save a new project however, I am getting this error.</p>
  
  <pre><code>Showing /home/james/Desktop/webapp/app/views/projects/new.html.erb where line #233 raised:
  
      undefined method `model_name' for NilClass:Class
  
  Extracted source (around line #233):
  
  233: &lt;%= fields_for(@project_technol) do |ab| %&gt;
  234: 
  235: &lt;div class="tech"&gt;
  236: &lt;%= ab.label "All Tech" %&gt;&lt;br/&gt;
  </code></pre>
  
  <p>I am new to rails and still learning so please remember when answering. Thanks in advance.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>after changing</p>
  
  <pre><code>@project.projecttechnols.build(:technol_id =&gt; technol)
  </code></pre>
  
  <p>to</p>
  
  <pre><code>@project_technol = @project.projecttechnols.build(:technol_id =&gt; technol)
  </code></pre>
  
  <p>I now get this error:</p>
  
  <pre><code>NoMethodError in Projects#create
  
  undefined method `map' for nil:NilClass
  
  Extracted source (around line #240):
  
  237: &lt;div class="tech"&gt;
  238: &lt;%= ab.label "All Tech" %&gt;&lt;br/&gt;
  239: 
  240: &lt;%= collection_select(:technols, :id, @all_technols, :id, :tech, {}, {:multiple =&gt; true} ) %&gt;
  241: &lt;/div&gt;
  242: &lt;% end %&gt;
  </code></pre>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>@all_technols = Technol.all in the create action </p>
  
  <p>I now get this error.</p>
  
  <pre><code>NoMethodError in Projects#show
  
  Showing /home/james/Desktop/webapp/app/views/projects/show.html.erb where line #181 raised:
  
  undefined method `technol' for #&lt;Project:0xb36823c&gt;
  Extracted source (around line #181):
  
  178: &lt;h3&gt;Related books&lt;/h3&gt;
  179: 
  180: &lt;ul&gt;
  181:   &lt;% @project.technol.each do |technol| %&gt;
  182:     &lt;li&gt;&lt;%= technol.tech %&gt; &lt;%= link_to "Details", technol_path(technol) %&gt;&lt;/li&gt;
  183:   &lt;% end %&gt;
  184: &lt;/ul&gt;
  </code></pre>