I’m new to Rails (and liking it!) and I have multiple controllers, each
of which has a method which uses a view template which is identical to
what the others use.
I would like to be able to have just one template to maintain that they
can all use. What is the customary way to do this? I tried using
render_action to specify the template explicitly, and it “works”. But I
would like to be able to redirect to this method without getting a “Can
only render or redirect once per action” error.
Thanks for any assistance!
-Steve B.
Steve B. wrote:
I’m new to Rails (and liking it!) and I have multiple controllers, each
of which has a method which uses a view template which is identical to
what the others use.
I would like to be able to have just one template to maintain that they
can all use. What is the customary way to do this? I tried using
render_action to specify the template explicitly, and it “works”. But I
would like to be able to redirect to this method without getting a “Can
only render or redirect once per action” error.
Thanks for any assistance!
-Steve B.
Isn’t layout in Rails meant for this?
aj
Use sub-templates
http://api.rubyonrails.com/classes/ActionView/Base.html
When using the same rhtml for multiple methods in the same controller
(or multiple controllers where you’re passing just one object), use
partials:
http://api.rubyonrails.com/classes/ActionView/Partials.html
- dan
–
Dan K. mailto:[email protected]
http://www.dankohn.com/ tel:+1-415-233-1000
Dan K. wrote:
Use sub-templates
Peak Obsession
Thanks! Sub-templates look like just what I need.
-Steve