我正在使用Ruby on Rails 3.0.10,我想將一些參數傳遞給默認的呈現方法。也就是說,如果我有一個像如何將某些參數傳遞給默認呈現方法?
def show
...
respond_to do |format|
format.html # This, by default, renders the 'show.html.erb' file
end
end
一個代碼,我想傳遞一些參數,也許像(注:以下不工作)在show.html.erb
模板
def show
...
respond_to do |format|
# Here I would like to add some local objects that will be available in the 'show.html.erb' template file
format.html { render ..., :locals => { :content => { :value => 'Sample value' } } }
end
end
讓我可以是這樣的:
<%=
content[:value]
# => 'Sample value'
%>
在幾句話,我想通過相同的方式參數值,作爲關係到局部模板渲染製作關鍵:
render :partial,
:locals => {
:content => { :value => 'Sample value' }
}
我怎麼能這樣做?
我認爲問題中描述的方法(可能)比您提出的方法更好......您有任何理由按照您的建議去做?你有什麼建議? – Backo