Ruby why is my object saving without an ID? -


i feel i'm missing basic, , can @ , telling me is...

def create     @user = user.find_by_id(create_params[:user_id])     @plan = @user.plans.new(create_params)     if @plan.save        puts @plan.inspect     end end 

right puts statement returns this:

#<plan id: nil, zipcode: "02114", selected_plan: 5, user_id: 1> 

so basically.. attributes there, there's no id...

more info:

create_params = {zipcode:"02114", selected_plan:"5", user_id: 1} 

and if it's helpful know, save! work , saves plan id... , plan.save == true returns true

your code should have following pattern.

    @user = user.find(create_params[:user_id]) # see changes     @plan = @user.plans.new(create_params)     if @plan.save        puts @plan.reload.inspect  #reload object see if object has been saved!     else       puts @plan.errors.messages.inspect  # if object not saved there should object#errors.messages should have messages     end 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -