How to simplify "render_to_string" in Rails 3?

Viewed 18364

To render a partial in Rails 3 I do:

render 'my_partial', :my_object => my_value

To get partial's result as string I do:

render_to_string(:partial => 'my_partial', :layout => false, 
                 :locals => {:my_object => my_value})

Is this possible to write the last one shorter ? (e.g. to omit :partial or :locals like I do with render) (I tried, but get errors...)

4 Answers

You can always add your own method to ApplicationController and make it available as a helper method if you need to use it in views.

Related