ruby on rails - Couldn't find model without an ID (rails4 with strong parameters) -


i have 2 models user , order

in user model have following

class user < activerecord::base  include activemodel::forbiddenattributesprotection   has_many orders end 

in orders model, have

class order < activerecord::base  include activemodel::forbiddenattributesprotection   belongs_to user end 

in orders controller have

class orderscontroller < applicationcontroller  before_action :set_order, only: [:show, :edit, :update, :destroy]   def create    @user = user.find(params[:user_id])      @order = @user.orders.build(order_params)  respond_to |format|   if @order.save     format.html { redirect_to @order, notice: 'order created.' }     format.json { render action: 'show', status: :created, location: @order }   else     format.html { render action: 'new' }     format.json { render json: @orders.errors, status: :unprocessable_entity }   end end end    private    def order_params         params[:order].permit( :order_title, :propose_amount,       :terms,:users_attributes =>  [:user_id])    end  end 

on creating order, keep getting error below

    couldn't find user without id 

and following line higlighted line of error

    @user = user.find(params[:user_id])  

does knows heading wrong?


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -