在Rails视图中,如何在控制器中引用传递给respond_with的对象?

时间:2011-09-16 17:33:35

标签: ruby-on-rails respond-with

说我有以下内容:

class ProjectsController < ApplicationController
  responds_to :html

  def show
    @project = Project.find(params[:id])
    respond_with(@project)
  end
end

class UsersController < ApplicationController
  responds_to :html

  def show
    @user = User.find(params[:id])
    respond_with(@user)
  end
end

我是否可以使用一种方法在layouts / application.html.erb模板中引用传递给respond_with的对象,而无需知道指定变量的名称?

感谢。

1 个答案:

答案 0 :(得分:0)

没有方法(至少我没有听说过这种方法)。但如果你想要,你可以看看这里,这是非常好的解决方案:Decent exposure

我希望我能帮助你。