George Lucas
George Lucas

Reputation: 197

Ruby on Rails - Difference between Render and render action:

I'm having trouble understanding the difference between 'render' and 'render action:' in Ruby on Rails. I cannot find the answer to this.

render 'edit'
render action: :edit

Usually, edit is a RESTful method in a controller. When render 'edit' is called, the controller looks for a corresponding view file named edit.html.erb.

My initial guess is that both of these do the same thing. My question is what is the difference, if any between render 'action' and render action: 'action'? Is there any difference in performance speed? Is any convention favored over the other?

Thanks in advanced.

Upvotes: 2

Views: 509

Answers (2)

mswieboda
mswieboda

Reputation: 1026

From another SO answer: Difference between render :action and render :template

and Ruby on Rails Guide:

render :edit
render action: :edit
render "edit"
render "edit.html.erb"
render action: "edit"
render action: "edit.html.erb"
render "books/edit"
render "books/edit.html.erb"
render template: "books/edit"
render template: "books/edit.html.erb"
render "/path/to/rails/app/views/books/edit"
render "/path/to/rails/app/views/books/edit.html.erb"
render file: "/path/to/rails/app/views/books/edit"
render file: "/path/to/rails/app/views/books/edit.html.erb"

are all the same, no difference.

Upvotes: 2

ddavison
ddavison

Reputation: 29032

I'm pretty sure render 'edit' is just an attempt to save typability.

render 'edit'

Is just a synonym to:

render action: :edit

Is there any difference in performance speed?

If there is, it would be minuscule and probably favoring the action: :edit since a string to symbol might take longer

Upvotes: 2

Related Questions