我正在使用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