You could @ingredient = @recipe.ingredients.first
(if it is truly the only one, not sure how you could know this for sure.)
Assuming you already have the ingredient selected, as in a variable, you can set them like any other ActiveRecord object.
@ingredient = @recipe.ingredients.first
@ingredient.amount = 15 #or @ingredient.amount = params[:amount] (if you get the new value from POST)
@ingredient.unit = "Ounces"
@ingredient.save
If you just want to retrieve the attributes of each ingredient for a recipe and do something with them, like display them in some html tags in a view you could try this.
@ingredients = @recipe.ingredients
@ingredients.each do |ingr|
info = %w[amount, brand, id, recipe_id , unit].map do |attr|
ingr.send(attr)
end
at the end of each inner loop the array 'info' will be all the attributes of one ingredient.(assuming you include them in info array)
This is an example of a table you might use to store the associations, it should work with the rails :through => :recipe_ingedient
method:
CREATE TABLE `recipe_ingredient` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`recipe_id` int(11) NOT NULL,
`ingedient_id` int(11) NOT NULL,
`created_at` datetime DEFAULT NULL,
`updated_at` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci$$