ruby on rails - Why do I keep getting 'undefined method' when it's worked fine before? -


my orderscontroller follows below, keep getting message:

undefined method `listing_id=' #

extracted source (around line #31): 29 30 31 @order.listing_id = @listing.id

is there doing incorrectly? following tutorial followed instructions, when wasn't working decided copy , paste, , it's still not working. please, appreciated.

full code follows

    class orderscontroller < applicationcontroller        before_action :set_order, only: [:show, :edit, :update, :destroy]     before_action :authenticate_user!   def sales @orders = order.all.where(seller: current_user).order("created_at desc") end  def purchases @orders = order.all.where(buyer: current_user).order("created_at desc")    end     # /orders/new      def new        @order = order.new        @listing = listing.find(params[:listing_id])      end      # post /orders   # post /orders.json  def create @order = order.new(order_params) @listing = listing.find(params[:listing_id]) @seller = @listing.user   @order.listing_id = @listing.id @order.buyer_id = current_user.id @order.seller_id = @seller.id   stripe.api_key = env["stripe_api_key"] token = params[:stripetoken]  begin   charge = stripe::charge.create(     :amount => (@listing.price * 100).floor,     :currency => "usd",     :card => token     )   flash[:notice] = "thanks ordering!" rescue stripe::carderror => e   flash[:danger] = e.message end  respond_to |format|   if @order.save     format.html { redirect_to root_url, notice: 'order created.' }     format.json { render action: 'show', status: :created, location: @order }   else     format.html { render action: 'new' }     format.json { render json: @order.errors, status: :unprocessable_entity }   end end       end        private         # use callbacks share common setup or constraints between actions. def set_order     @order = order.find(params[:id]) end  # never trust parameters scary internet, allow white list through. def order_params   params.require(:order).permit(:address, :city, :state) end     end 

check fields of order model. have listing_id column on orders table ? check migration files make sure somewhere along way have added "listing_id" field "orders" table.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -