簡體   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