render is used to provide response of a request in rails. There are multiple kinds of responses that you can send with request. Lets see one by one:
By default if nothing is specified as render, actions are rendered withing in the current layout if they are present. In that case the template of that action gets rendered. If we specify the action in the render, the template of that action will get rendered:
# Renders the template for the action "index"
render :action => "index"
# Renders the template for the action "index", but doesn't use the currently set layout
render :action => "index", :layout => false
# Renders the template for the action "index", and uses the specified layout
render :action => "index", :layout => "some_layout"
Partials are used in multiple places, like in ajax calls when you want to update any particular portion of the page or you can also use them in views, to divide a large view into multiple pages.
a) Rendering with a collection:
In this case we can pass a collection to a partial and each will iterate over each element of the collection and will generate multiple appended views, i.e. in the example in each of the partial the user object will be available.
In this case the object with the partial name will be available in the partial
# @some_user will be available in user object
render :partial => "user", :object => @some_user
c) Using as:
We can provide custom name for the object
# @some_user will be available in person object in the partial
render :partial => "user", :object => @some_user, :as => :person
Rendering templates works similarly like the action, it takes the templates directly from the view according to its relative path. instance variables are always available in the partials or templates, you can also pass local variables using locals: