What does first.user = current_user mean/do and why is it working?
To start, I have 3 Models:

    Location has_many :products
    User has_many :products
    Products belongs_to :user, :location

Now i have a nested form:

    <%= nested_form_for @location do |f| %>
    <%= f.error_messages %>
    .............
    <% f.fields_for :products do |product| %>

I was trying to find the right way to get my current_user association to work and suddenly out of pure chance found the right answer in this question, http://stackoverflow.com/questions/2804854/nil-foreign-key-in-a-nested-form.

I put this piece of simple code in my controller and it finally gave my products to the current user_id:

    @location.products.first.user = current_user
full - 

    def create
        @location = Location.new(params[:location])
        @location.products.first.user = current_user
    end

My end goal was accomplished. Users have their own products created at the specific location. Only thing i don't understand is why `first.user = current_user` works and something simple like `location = @location.current_user.products.build` doesn't. Could someone give me a great explanation on whats going on here and what the former means? Is this OK to have or is their a safer/better way?

Thank you, i do appreciate it.
What does first.user = current_user mean/do and why is it working?
===

To start, I have 3 Models:

    Location has_many :products
    User has_many :products
    Products belongs_to :user, :location

Now i have a nested form:

    <%= nested_form_for @location do |f| %>
    <%= f.error_messages %>
    .............
    <% f.fields_for :products do |product| %>

I was trying to find the right way to get my current_user association to work and suddenly out of pure chance found the right answer in this question, http://stackoverflow.com/questions/2804854/nil-foreign-key-in-a-nested-form.

I put this piece of simple code in my controller and it finally gave my products to the current user_id:

    @location.products.first.user = current_user
full - 

    def create
        @location = Location.new(params[:location])
        @location.products.first.user = current_user
    end

My end goal was accomplished. Users have their own products created at the specific location. Only thing i don't understand is why `first.user = current_user` works and something simple like `location = @location.current_user.products.build` doesn't. Could someone give me a great explanation on whats going on here and what the former means? Is this OK to have or is their a safer/better way?

Thank you, i do appreciate it.