당신은 @ingredient = @recipe.ingredients.first
, 당신은 어떤처럼 그들을 설정할 수 수 다른 ActiveRecord 객체.
@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
당신은 당신이 시도 할 수있는보기에서 일부 HTML 태그를 표시 같은 조리법에 대한 각 성분의 특성을 검색하고 그들과 함께 무언가를 할 경우
. 각각의 내부 루프 배열 '정보'의 끝 부분에
@ingredients = @recipe.ingredients
@ingredients.each do |ingr|
info = %w[amount, brand, id, recipe_id , unit].map do |attr|
ingr.send(attr)
end
한 성분의 모든 속성 될 것입니다. (가정 당신이 정보를 배열에 포함)
이 당신이 수도 테이블의 예입니다 협회를 저장하는 데 사용, 그것은 레일 :through => :recipe_ingedient
방법으로 작동합니다 :
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$$
당신이 원하는 레시피를 발견 했으므로, 해당 레시피를위한 재료를 찾았습니다. 이 성분 중 하나의 속성을 편집 하시겠습니까? 아니면 이전에 선택한 레서피에 대해 새로운 성분을 추가 하시겠습니까? 또는 채우려는 성분의 다른 조인 테이블이 있습니까? – holaSenor
레시피와 성분에 대한 조인 테이블이 있는데, 조인 테이블은 레시피와 관련된 성분, 즉 각 성분의 양에 관한 정보를 담고 있습니다. –