Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 530035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:09:15+00:00 2026-05-13T09:09:15+00:00

I have a table called order which has many order_items , each order_items is

  • 0

I have a table called “order” which has many “order_items” , each “order_items” is belongs_to “order” and “product”. In the db, I have one record in order. the record is like this:

orders table:
id = 1
name= customer

and the order_items table is like this:
id=1
product_id=233
order_id =1

id=2
product_id=454
order_id =1

I am trying to this code to show the order, but it is not success:

<% semantic_form_for @order do |f| %>  
  <% f.inputs do %>  
    <%= f.input :name %>  

  <% end %>  
  <%= f.buttons %>  
<% end %>

and this is my order.rb:

class Order < ActiveRecord::Base
  has_many :order_items



end

last but not least, this is the controller of order.rb:

class OrderController < ApplicationController
  # GET /orders
  # GET /orders.xml
  def index
    @orders = order.all

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @orders }
    end
  end

  # GET /orders/1
  # GET /orders/1.xml
  def show
    @order = order.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @order }
    end
  end

  # GET /orders/new
  # GET /orders/new.xml
  def new
    @order = order.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @order }
    end
  end

  # GET /orders/1/edit
  def edit
    @order = order.find(params[:id])
  end

  # POST /orders
  # POST /orders.xml
  def create
    @order = order.new(params[:order])

    respond_to do |format|
      if @order.save
        flash[:notice] = 'order was successfully created.'
        format.html { redirect_to(@order) }
        format.xml  { render :xml => @order, :status => :created, :location => @order }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @order.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /orders/1
  # PUT /orders/1.xml
  def update
    @order = order.find(params[:id])

    respond_to do |format|
      if @order.update_attributes(params[:order])
        flash[:notice] = 'order was successfully updated.'
        format.html { redirect_to(@order) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @order.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /orders/1
  # DELETE /orders/1.xml
  def destroy
    @order = order.find(params[:id])
    @order.destroy

    respond_to do |format|
      format.html { redirect_to(orders_url) }
      format.xml  { head :ok }
    end
  end
end

And this is the error from RoR:

Called id for nil, which would
mistakenly be 4 — if you really
wanted the id of nil, use object_id

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:09:15+00:00Added an answer on May 13, 2026 at 9:09 am

    Classes in ruby have to be uppercased:

    Order # class
    order # variable or method
    

    this should work:

    class OrderController < ApplicationController
      def show
        @order = Order.find(params[:id])
    
        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml => @order }
        end
      end
      # ...
    end
    

    in your show.html.erb:

    #...
    <%= @order.name =>
    #...
    

    url:

    /orders/:id
    

    if you want, let’s say a standard edit form:

    # edit.html.erb
    
    <% form_for @order do |f| %>  
      <%= f.input :name %>   
      # fields
      <%= f.submit "Place order" %>  
    <% end %>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 256k
  • Answers 256k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How about /<([\w\[\].]+)\s*"?([^">]*)"?>/ or /<(\w+)\s*"?([^">]*)"?>/ if your A[1..80] means \w… May 13, 2026 at 10:35 am
  • Editorial Team
    Editorial Team added an answer After carefully considering my own plans for the application, I've… May 13, 2026 at 10:35 am
  • Editorial Team
    Editorial Team added an answer if(passnew.Length == passcnfrm.Length && passnew.Length > 6 && passnew.Length <… May 13, 2026 at 10:35 am

Related Questions

I'm betting that someone has already solved this and maybe I'm using the wrong
I have a sql server 2005 table called ZipCode, which has all the US
i have a table that has zero to many children. just like how this
I have a table containing user input which needs to be optimized. I have
I've got a table containing many rows. The rows are guaranteed to have been

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.