title: Ruby on rails NoMethodError in controller after create an association
body: <p>I have two models User and Promotion, an user can create has_many promotion and an promotion belong to user so :</p>
  
  <p>promotion.rb</p>
  
  <pre><code>class Promotion &lt; ActiveRecord::Base
  belongs_to :user
  belongs_to :good
  
  validates :name,  :presence =&gt; true
  validates :title, :presence =&gt; true
  validates :description, :presence =&gt; true
  
  
  end
  </code></pre>
  
  <p>for the users i used devise so:</p>
  
  <p>user.rb</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
  
  has_many :promotions  ,:foreign_key =&gt; "user_id",
     :dependent =&gt; :destroy
  
  
  
  devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable, :validatable,
       :omniauthable, :omniauth_providers =&gt; [:facebook]
  # Setup accessible (or protected) attributes for your model
   attr_accessible :email, :password, :password_confirmation, :remember_me,:provider,:uid,:address,:name,:surname,:supplier,:partita_iva,:state,
                :gender ,:language,:bio,:work,:education
  </code></pre>
  
  <p>now when i want create a new promotions get this error </p>
  
  <p><strong>NoMethodError in PromotionsController#create
  undefined method `promotions' for nil:NilClass</strong></p>
  
  <p>this is the controller:</p>
  
  <pre><code> def create
  @user = User.find_by_id(params[:user_id])
  @promotion =@user.promotions.create(:params[:promotion])
  redirect_to promotion_patch(@promotion)
  
  respond_to do |format|
    if @promotion.save
      format.html { redirect_to @promotion, notice: 'Promotion was successfully created.' }
      format.json { render json: @promotion, status: :created, location: @promotion }
    else
      format.html { render action: "new" }
      format.json { render json: @promotion.errors, status: :unprocessable_entity }
    end
  end
  end
  </code></pre>
  
  <p>help please :)</p>