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 3677032
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T03:10:20+00:00 2026-05-19T03:10:20+00:00

I have been debugging this the entire day. I have two models in my

  • 0

I have been debugging this the entire day.
I have two models in my application: teaClass & tea. In teaclass.rb, I have

has_many :teas

In tea.rb, I have ‘belongs_to :teaclass`.

I try to make the url looks like this "..teaclasses/:id/teas/:id"; so in teas_controller.rb, I put before_filter :get_teaClass

def show
@tea = @teaclass.teas.find(params[:id])

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

def new
if @teaclass.teas
    @tea = @teaclass.teas.new
    @teaclass.teas << @tea 
    #@tea = Tea.new
    else
        flash[:notice=>"failed"]
        @tea = Tea.new 
        @teaclass.teas << @tea 
    end
respond_to do |format|
  format.html # new.html.erb
  format.xml  { render :xml => @tea }
end
end

def get_teaClass
    begin
        @teaclass = Teaclass.find(params[:teaclass_id])rescue
        redirect_to teaclass_path, :notice => "Teaclass Required!"
    end
 end

But I keep getting an error saying “unknown attribute: teaclass_id”

/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2906:inassign_attributes'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `each'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2902:in `assign_attributes'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2474:in `initialize'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in `new'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:380:in `method_missing'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/base.rb:2178:in `with_scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:207:in `send'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_proxy.rb:207:in `with_scope'
/usr/lib/ruby/gems/1.8/gems/activerecord-2.3.8/lib/active_record/associations/association_collection.rb:376:in `method_missing'
/home/jianpchen/repo/Teashop/app/controllers/teas_controller.rb:31:in `new'

Can anyone help me on this? Thank you.

  • 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-19T03:10:21+00:00Added an answer on May 19, 2026 at 3:10 am

    I try to make the url looks like this “..teaclasses/:id/teas/:id”; so in teas_controller.rb, I put before_filter :get_teaClass

    This only matters if you are trying to get nested routes setup but id doesn’t sound like you are doing that.

    What you need to do is actually add the foreign id to the database. So check schema.rb and make sure that column exists.

    Here is what you need to do.

    1. Make sure you actually have the foreign in the database table tea.
    2. If you do skip to the next step where I will show you a better way to write your code.
    3. If you do not have ‘tea_class_id’ as an integer value on your ‘tea’ table you need to add it.
    4. script/generate migration add_tea_class_id_to_tea
    5. rake db:migrate
    6. Now This is how your code should be written

    routes.rb

    map.resources :teas
    map.resources :teas_classes
    

    Models

    models/tea.rb

    class Tea < ActiveRecord::Base
        belongs_to :tea_class
    end 
    

    tea_class.rb

    class TeaClass < ActiveRecord::Base
        has_many :teas
    end 
    

    controllers

    teas_controller.rb

    def new
       @tea = Tea.new
    end
    
    def show
      @tea = tea.find(params[:id)
    end
    
    def create
        @tea = Tea.new(params[:tea])
        if @tea.save
            redirect_to teas_path
        else
            render :action => 'new'
        end
    end 
    

    views

    This is really important. Make sure you are passing the :tea_class_id as a parameter when you create a tea otherwise it doesn’t know how to make the association. It’s kinda behind the stage because you send params[:tea] but it is in those parameters where the tea_class_id is actually sent.

    So… in your view you need to have some sort of way for users to choose a category or as you have it tea class and that is usually done with a select box when it is a one to many association.

    new.html.erb

    <% form_for(@tea) do |t| %>
        <%= t.collection_select :tea_class_id TeaClass.all, :id, :name %>
    <% end %>
    

    Make sure you have tea classes to actually fill the collection_select method. Google that plus rails api if you don’t get what’s going on.

    Nested Routes (on the side)

    Looked like you were trying to get the routes like teaclasses/:id/teas/:id. This is called nested routing and you will want to set that up in your routes.rb

    map.resources :tea_classes_ do |tea_classes|
       tea_classes :teas
    end
    map.resources :teas
    

    Then you can link to teas_classes/pour/teas/chinese. You should know this command rake routes. It will help you understand how the paths work.

    But if you just want the link to get going it should be like this:

    <%= link_to "Teas", tea_classes_teas_path(@tea_class)%>
    

    You need to supply @teas do the link because it takes the id from that and when you click it gives it to the teas_controller' asparams[:teas_class_id]`. You don’t need to do anything without. It will automatically be in the url.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have recently been put in charge of debugging two different programs which will
I have been debugging this query for the last 40 minutes, and the problem
Is OutputDebugString(PAnsiChar('')); thread safe? I/we have been using it in threads for debugging, and
We've been debugging this JBoss server problem for quite a while. After about 10
I have a been working on a game for Android and debugging it on
I have been debugging a program for some time. The code below is part
I have been debugging in GDB (C code). The issue is if I run
I have a working WCF service and worker role that I have been debugging
I have been debugging the infamous EXC_BAD_ACCESS error for a few days now. NSZombieEnabled
I have been debugging my app and checking the memory allocation and came across,

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.