Ruby on rails RubyonRails重用视图

Ruby on rails RubyonRails重用视图,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我有一张“食谱”表和一张“配料”表。每个配方“有很多”成分,每个成分“有很多”配方 我想在配料页面添加一个链接:“显示所有含有该配料的配方” 我在配料控制器中编写了以下代码: def recipes @ingredient = Ingredient.find(params[:id]) @recipes = @ingredient.recipes respond_to do |format| format.html # index.html.erb

我有一张“食谱”表和一张“配料”表。每个配方“有很多”成分,每个成分“有很多”配方

我想在配料页面添加一个链接:“显示所有含有该配料的配方”

我在配料控制器中编写了以下代码:

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”视图(recipes/index.html.erb)中使用的相同代码。 如何将rails定向到此视图

(我使用的是rails 3.x)

谢谢, 李像这样:

def recipes
    @ingredient = Ingredient.find(params[:id])
    @recipes = @ingredient.recipes
    respond_to do |format|
       format.html { render "recipes/index" }
       format.json { render json: @recipes }
    end
end
有关详细信息,请参阅rails指南: