I am using Ruby on Rails 3.0.10 and I would like to pass some parameters to the default rendering method. That is, if I have a code like
def show
...
respond_to do |format|
format.html # This, by default, renders the 'show.html.erb' file
end
end
I would like to pass some parameters, maybe like (note: the following doesn’t work)
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
so that in the show.html.erb template I can make something like:
<%=
content[:value]
# => 'Sample value'
%>
In few words, I would like to pass parameter values in the same way as made for partial template rendering related to the :locals key:
render :partial,
:locals => {
:content => { :value => 'Sample value' }
}
How can I do that?
You can do exactly what you described. I looked it up here http://apidock.com/rails/ActionController/Base/render under the heading “Rendering a template” and gave it a whirl myself. You learn something new everyday.
You can simply do
I would consider why you need to do this instead of using instance variables. Maybe there is a better approach.