
- Learning Ruby on Rails
- Rails 2.1 Home
- Rails 2.1 Introduction
- Rails 2.1 Installation
- Rails 2.1 Framework
- Rails 2.1 Dir Structure
- Rails 2.1 Examples
- Rails 2.1 Database Setup
- Rails 2.1 Active Records
- Rails 2.1 Migrations
- Rails 2.1 Controllers
- Rails 2.1 Views
- Rails 2.1 Layouts
- Rails 2.1 Scaffolding
- Rails 2.1 and AJAX
- Rails 2.1 Uploads Files
- Rails 2.1 Sends Emails
- Advanced Ruby on Rails 2.1
- Rails 2.1 RMagick Guide
- Rails 2.1 Basic HTTP Auth
- Rails 2.1 Error Handling
- Rails 2.1 Routes System
- Rails 2.1 Unit Testing
- Advanced Ruby on Rails 2.1
- Rails 2.1 Tips & Tricks
- Quick Reference Guide
- Quick Reference Guide
- Ruby on Rails 2.1 Useful Resources
- Ruby on Rails 2.1 - Resources
- Ruby on Rails 2.1 - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Ruby on Rails 2.1 - 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
It is more like rendering an action, but it 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.rhtml' render :file => '/path/to/some/filenotfound.rhtml', 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-quick-guide.htm
Advertisements