
- Ruby on Rails Tutorial
- Ruby on Rails - Home
- Ruby on Rails - Introduction
- Ruby on Rails - Installation
- Ruby on Rails - Framework
- Ruby on Rails - Directory Structure
- Ruby on Rails - Examples
- Ruby on Rails - Database Setup
- Ruby on Rails - Active Records
- Ruby on Rails - Migrations
- Ruby on Rails - Controllers
- Ruby on Rails - Routes
- Ruby on Rails - Views
- Ruby on Rails - Layouts
- Ruby on Rails - Scaffolding
- Ruby on Rails - AJAX
- Ruby on Rails - File Uploading
- Ruby on Rails - Send Emails
- Ruby on Rails Resources
- Ruby on Rails - References Guide
- Ruby on Rails - Quick Guide
- Ruby on Rails - Resources
- Ruby on Rails - Discussion
- Ruby Tutorial
- Ruby Tutorial
Ruby on Rails - Render
Usually the view template with the same name as the controller method is used to render the results.
Action
# The default. Does not need to be specified # in a controller method called "some_action" render :action => 'some_action' render :action => 'another_action', :layout => false render :action => 'some_action', :layout => 'another_layout'
Partial
Partials are stored in files called "_subformname" ( _error, _subform, _listitem).
render :partial => 'subform' render :partial => 'error', :status => 500 render :partial => 'subform', :locals => { :variable => @other_variable } render :partial => 'listitem', :collection => @list render :partial => 'listitem', :collection => @list, :spacer_template => 'list_divider'
Template
Like rendering an action, but finds the template based on the template root (app/views).
# renders app/views/weblog/show render :template => 'weblog/show'
File
render :file => '/path/to/some/file.html.erb' render :file => '/path/to/some/filenotfound.html.erb', status => 404, :layout => true
Text
render :text => "Hello World" render :text => "This is an error", :status => 500 render :text => "Let's use a layout", :layout => true render :text => 'Specific layout', :layout => 'special'
Inline Template
Uses ERb to render the "miniature" template
render :inline => "<%= 'hello , ' * 3 + 'again' %>" render :inline => "<%= 'hello ' + name %>", :locals => { :name => "david" }
Nothing
render :nothing render :nothing, :status => 403 # forbidden
RJS
def refresh render :update do |page| page.replace_html 'user_list', :partial => 'user', :collection => @users page.visual_effect :highlight, 'user_list' end end
Change the content-type −
render :action => "atom.rxml", :content_type => "application/atom+xml"
rails-references-guide.htm
Advertisements