
- 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 - Controller Methods
Each public method in a controller is callable by the (standard) URL scheme /controller/action.
class WorldController < ApplicationController def hello render :text => 'Hello world' end
Parameters are stored in the params hash −
/world/hello/1?foo = bar id = params[:id] # 1 foo = params[:foo] # bar
Instance variables defined in the the controllers methods are available to the corresponding view templates −
def show @person = Person.find( params[:id]) end
Distinguish the type of response accepted −
def index @posts = Post.find :all respond_to do |type| type.html # using defaults, which will render weblog/index.html.erb type.xml { render :action => "index.rxml" } type.js { render :action => "index.rjs" } end end
rails-references-guide.htm
Advertisements