2012-06-16 27 views
1

我有一個「食譜」表和一個「成分」表。每個食譜「has_and_belong_to_many」成分和每個成分「has_and_belong_to_many」食譜。紅寶石在軌道上重用視圖

我想添加一個鏈接到配料頁面:「顯示所有包含這種成分的食譜」。

我寫了下面的代碼在我的配料控制器:

def recipes 
    @ingredient = Ingredient.find(params[:id]) 
    @recipes = @ingredient.recipes 
    respond_to do |format| 
     format.html # index.html.erb 
     format.json { render json: @recipes } 
    end 
end 

我的問題是,現在它希望我有下的「成分」視圖「recipes.html.erb」文件。 我不想爲此創建一個新視圖,我只想使用在「食譜」視圖(recipes/index.html.erb)中使用的相同代碼。 如何將導軌引導至此視圖?

(我使用的軌道3.X)

感謝, 李

回答