我可以做为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
我想传递一些参数,可能像这样(注意:以下内容不起作用)
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
这样在show.html.erb
模板中,我就可以做出如下的内容:
<%=
content[:value]
# => 'Sample value'
%>
简而言之,我希望能以与局部模板渲染相关的:locals
键相同的方式传递参数值:
render :partial,
:locals => {
:content => { :value => 'Sample value' }
}
我该怎么做?