简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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