Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Usage of render and render partial

For rendering a partial I can use

render 'partial_name' or render partial: 'partial_name'

I came to know that render is the shorthand syntax of render partial and render will not accept additional local variables for the partial from this SO answer

I would like to know if there is any performance issue when using render instead of render partial

like image 972
webster Avatar asked Mar 26 '26 12:03

webster


1 Answers

In Rails, the render action

"Renders the content that will be returned to the browser as the response body."

It is possible to render an action, text, the contents of a file, and other things, including a partial view.

render :action => "Create"
render :file => "/path/to/file/foo.erb", :layout => true, :status => 404
render :partial =>...

Using the partial label explicitly, disambiguates the render action for Rails ActionController.

As far as performance, I haven't done the test to confirm, but I think it's reasonable to expect it is more efficient to use render :partial for the above reasons.

When I'm looking for the nuts & bolts underlying Rails logic, this is an excellent detailed technical reference.

like image 188
Elvn Avatar answered Mar 29 '26 02:03

Elvn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!