Take the 2-minute tour ×  Hi (huge Rails newbie here), I have
the following models:  class Shop < ActiveRecord::Base
belongs_to :user   validates_uniqueness_of :title, :user_id,
:message => "is already being used"   class User <
ActiveRecord::Base   has_one :shop, :dependent => :destroy  When
I'm about to create a new shop, I get the following error:
private method `create' called for nil:NilClass  This is my
controller:  @user = current_user @shop =
@user.shop.create(params[:shop])  I've tried different
variations by reading guides and tutorials here and there, but
I'm more confused than before and can't get it to work. Any help
would be greatly appreciated.  share|improve this question
Edited question title to reflect question. Duplicate of Using
build with a has_one association in rails –  Marc-André
Lafortune May 9 '12 at 18:53 add comment  2 Answers  up vote 21
down vote accepted  First of all, here is how to do what you
want:  @user = current_user @shop = Shop.create(params[:shop])
@user.shop = @shop