[英]In a Rails view how do I reference the object passed to respond_with in the controller?
Say I have the following: 说我有以下几点:
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
Is there a method I can use to reference the object passed to respond_with in the layouts/application.html.erb template without needing to know the assigned variable's name? 我是否可以使用一种方法来引用在layouts / application.html.erb模板中传递给response_with的对象,而无需知道分配的变量的名称?
Thanks. 谢谢。
No there is no method(at least I didn't hear about such method). 没有方法(至少我没有听说过这种方法)。 But if you want you can look here, it is pretty nice solution: Decent exposure
但是,如果您愿意,可以看看这里,这是一个非常不错的解决方案: 适当的曝光
I hope I helped you alittle. 希望我能帮到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.