- Ruby on Rails - Send Emails
- Ruby on Rails - File Uploading
- Ruby on Rails - AJAX
- Ruby on Rails - Scaffolding
- Ruby on Rails - Layouts
- Ruby on Rails - Views
- Ruby on Rails - Routes
- Ruby on Rails - Controllers
- Ruby on Rails - Migrations
- Ruby on Rails - Active Records
- Ruby on Rails - Database Setup
- Ruby on Rails - Examples
- Ruby on Rails - Directory Structure
- Ruby on Rails - Framework
- Ruby on Rails - Installation
- Ruby on Rails - Introduction
- Ruby on Rails - Home
Ruby on Rails Resources
- Ruby on Rails - Discussion
- Ruby on Rails - Resources
- Ruby on Rails - Quick Guide
- Ruby on Rails - References Guide
Ruby Tutorial
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Ruby on Rails - Routes
The routing module provides URL rewriting in native Ruby. It s a way to redirect incoming requests to controllers and actions. It replaces the mod_rewrite rules. Best of all, Rails Routing works with any web server. Routes are defined in app/config/routes.rb.
Think of creating routes as drawing a map for your requests. The map tells them where to go based on some predefined pattern −
Rails.apppcation.routes.draw do Pattern 1 tells some request to go to one place Pattern 2 tell them to go to another ... end
Example
Let us consider our pbrary management apppcation contains a controller called BookController. We have to define the routes for those actions which are defined as methods in the BookController class.
Open routes.rb file in pbrary/config/ directory and edit it with the following content.
Rails.apppcation.routes.draw do get book/pst get book/new post book/create patch book/update get book/pst get book/show get book/edit get book/delete get book/update get book/show_subjects end
The routes.rb file defines the actions available in the apppcations and the type of action such as get, post, and patch.
Use the following command to pst all your defined routes, which are useful for tracking down routing problems in your apppcation, or giving you a good overview of the URLs in an apppcation you re trying to get famipar with.
pbrary> rake routes
What is Next?
Next, we will create the code to generate screens to display data and to take input from the user.
Advertisements