I have an Ingredient which has a Measurement.

class Ingredient < ActiveRecord::Base
  has_one :measurement
  belongs_to :recipe

  accepts_nested_attributes_for :measurement
end

class Measurement < ActiveRecord::Base
  belongs_to :ingredient
end


The schemas appear right:

  create_table "ingredients", :force => true do |t|
    t.integer  "measurement_id"
    t.integer  "recipe_id"
    t.string   "quantity"
    t.string   "food"
    t.datetime "created_at"
    t.datetime "updated_at"
  end


  create_table "measurements", :force => true do |t|
    t.string   "size"
    t.float    "quantity"
    t.string   "abbreviation"
    t.string   "measurement"
    t.string   "measurement_type"
    t.string   "equivalent"
    t.datetime "created_at"
    t.datetime "updated_at"
  end



But I'm still getting this error preventing me from doing an
ingredient.measurement.abbreviation, but ingredient.measurement_id
works:

ActiveRecord::StatementInvalid in Recipes#show

Showing /Users/mkidd/Sites/cookbook/app/views/recipes/show.html.erb
where line #14 raised:

SQLite3::SQLException: no such column: measurements.ingredient_id:
SELECT  "measurements".* FROM "measurements" WHERE
("measurements".ingredient_id = 1) LIMIT 1

Extracted source (around line #14):

11: <% for ingredient in @recipe.ingredients%>
12:   <li>
13:     <%= ingredient.quantity %>
14:   <%= ingredient.measurement %>
15:     <%= ingredient.food %>
16:   </li>
17: <% end %>

-- 
Posted via http://www.ruby-forum.com/.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to