title: Rails association - difficulty getting form_for to work
body: <p>I have a Member model that belongs to User</p>
  
  <pre><code>class Member &lt; ActiveRecord::Base
  
      attr_accessible :name
      belongs_to :user
  
  end
  
  
  class User &lt; ActiveRecord::Base
  
      attr_accessible :name
      has_many :members, :dependent =&gt; :destroy
  
  end
  </code></pre>
  
  <p>In my Members controller I have</p>
  
  <pre><code>class MembersController &lt; ApplicationController
  
    def create
      @user = User.find(params[:user_id])
      @member  = @user.members.build(params[:member])
      if @member.save
        flash[:success] = "Member created!"
        redirect_to root_path
      else
        render 'pages/home'
      end
    end
  end
  </code></pre>
  
  <p>In /app/views/users/show.html.erb I have</p>
  
  <pre><code>&lt;%= form_for @member do |f| %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.text_area :name %&gt;
    &lt;/div&gt;
    &lt;div class="actions"&gt;
      &lt;%= f.submit "Submit" %&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>But I get the following error:
      undefined method `model_name' for NilClass:Class</p>
  
  <pre><code>Extracted source (around line #18):
  
  15: 
  16: &lt;h1 class="member"&gt;What's up?&lt;/h1&gt;
  17: 
  18: &lt;%= form_for @member do |f| %&gt;
  </code></pre>
  
  <p>My show action in the Users controller is</p>
  
  <pre><code>  def show
        @user = User.find(params[:id])
        @members = Member.new
        @title = @user.name
    end
  </code></pre>
  
  <p>Which also contains the 'new' method</p>
  
  <p>I have tried changing :user_id to :id in the MembersController but this does not work either. What am I doing wrong here?</p>
  
  <p>thanks in advance </p>