2012-12-06 15 views

回答

2

此處至少有2個選項。

最簡單的一種是使用action_params

def read page 
    # use action_params[:page] in templates 
end 

請注意,這僅適用於Ruby 1.9的

在Ruby 1.8使用action_params[0]

另一種方式是通過您的PARAMS作爲上下文變量:

def profile user 
    render :user => user 
    # in templates, user is available as #user getter 
    # rather than @user instance variable 
end 
+0

感謝,不知道'action_params' –

1

查看源代碼,如果將散列傳遞給渲染函數,則會將這些鍵作爲局部變量分配給視圖。像

render(:foo => "Bar") 
在行動

,然後東西在視圖中,你可以做

<%= foo %> 

這將使

Bar 
相關問題