Search code examples
ruby-on-railsrendering

Difference between render :action and render :template


What is the difference between render :action => "new" and render :template => "users/new"? I have heard that rendering template, we can use for views from other controllers. Is that it or is there any difference in rendering layout also between the two? For render :template, is it neccessary to have an action defined or is the view page itself enough?


Solution

  • There is no difference.
    render :template => 'some/thing' is the same as just render 'some/thing', as well as the same as render :action => 'thing' if we are in the some controller.

    From 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'