Difference between render :action and render :template

前端 未结 3 1599
无人及你
无人及你 2020-12-07 16:57

What is the difference between render :action => \"new\" and render :template => \"users/new\"? I have heard that rendering template, we can

相关标签:
3条回答
  • 2020-12-07 17:25

    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'
    
    0 讨论(0)
  • 2020-12-07 17:27

    Previously, calling render "foo/bar" in a controller action was equivalent to render file: "foo/bar". In Rails 4.2, this has been changed to mean render template: "foo/bar" instead. If you need to render a file, please change your code to use the explicit form (render file: "foo/bar") instead.

    http://guides.rubyonrails.org/4_2_release_notes.html#render-with-a-string-argument

    0 讨论(0)
  • 2020-12-07 17:35
     render :action => 'some_controller_action', :layout => 'some_layout_in_layout_folder'
    

    will render the view of that controller action and apply the asset settings (javascript, CSS) of the some_layout_in_layout_folder layout.

    If you write this in a controller action, it will use the styling of the specified layout in conjunction with any layout defined at the beginning of the class, if any

    0 讨论(0)
提交回复
热议问题