繁体   English   中英

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

[英]In a Rails view how do I reference the object passed to respond_with in the controller?

说我有以下几点:

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模板中传递给response_with的对象,而无需知道分配的变量的名称?

谢谢。

没有方法(至少我没有听说过这种方法)。 但是,如果您愿意,可以看看这里,这是一个非常不错的解决方案: 适当的曝光

希望我能帮到你。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM