recording current_user

there's a few ways of doing this:

1) outlet = Outlet.new(params[:outlet])
outlet.user = current_user()
outlet.save!

2) @user = current_user()
#returns a new object of the collection type that has been
instantiated with attributes and linked to this object through the
join table but has not yet been saved.
@user.outlets.build(params[:outlet])
@user.save!

3) @user = current_user()
#returns a new object of the collection type that has been
instantiated with attributes and linked to this object through the
join table
@user.outlets.create(params[:outlet])

4) @user = current_user()
#adds one or more objects to the collection by creating associations
in the join table
@user.outlets << Outlet.new(params[:outlet])

see here for more info:

http://api.rubyonrails.com/classes/ActiveRecord/Associations/ClassMethods.html#M000645

Adam

If you're doing something like this:

@user = current_user()
@user.outlets.create(params[:outlet])

and you're getting that error, it means that @user is nil. Make sure
that current_user() actually returns a valid user before attempting to
add outlets to them.

Adam