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...)
Doesn't seem like it could get any shorter, Ref. If you feel it's too long you could hide it in a helper method, and just pass the various params?
Sometimes you could do something like
render_to_body "path_to_file"
and it skips layout but still you have to use instance variables inside your partial.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With