Ruby On Rails Classroom image

Neha  Jaggi / Professional / Web Technology

 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3|Last
Lessons:-MVC in Action

You may notice that there are more actions than there are pages; the index, show, new, and edit actions all correspond to pages from Section 2.2.1, but there are additional create, update, and destroy actions as well. These actions don’t typically render pages (although they sometimes do); instead, their main purpose is to modify information about users in the database. This full suite of controller actions, summarized in Table 2.2, represents theimplementation of the REST architecturein Rails (Box 2.2), which is based on the ideas of representational state transfer identified and named by

Table 2.2 RESTful routes provided by the Users resource in Listing 2.2.

HTTP request                           URI                                 Action                                             Purpose
GET                                        /users                              index                                             page to list all users
GET                                        /users/1                           show                                             page to show user with id 1
GET                                       /users/new                         new                                              page to make a new user
POST                                      /users                               create                                          create a new user
GET                                       /users/1/edit                       edit                                                page to edit user with id 1
PUT                                        /users/1                            update                                            update user with id 1
DELETE                                 /users/1                              destroy                                           delete user with id 1

computer scientist Roy Fielding.4 Note from Table 2.2 that there is some overlap in the URIs; for example, both the user show action and the update action correspond to the URI /users/1. The difference between them is the HTTP request method they respond to. We’ll learn more about HTTP request methods starting in Section 3.2.1.  

Box 2.2 REpresentational State Transfer (REST)
If you read much about Ruby on Rails web development, you’ll see a lot of references to ‘‘REST,’’ which is an acronym for REpresentational State Transfer. REST is an architectural style for developing distributed, networked systems and software applications such as the World Wide Web and web applications. Although REST theory is rather abstract, in the context of Rails applications REST means that most application components (such as users and microposts) are modeled as resources that can be created, read, updated, and deleted—operations that correspond both to the CRUD operations of relational databases and the four fundamental HTTP request methods: POST, GET, PUT, and DELETE. (We’ll learn more about HTTP requests in Section 3.2.1 and especially Box 3.2.)
As a Rails application developer, the RESTful style of development helps you make choices about which controllers and actions to write: You simply structure the application using resources that get created, read, updated, and deleted. In the case of users and microposts, this process is straightforward, since they are naturally resources in their own right. In Chapter 11, we’ll see an example where REST principles allow us to model a subtler problem, ‘‘following users,’’ in a natural and convenient way.

To examine the relationship between the Users controller and the User model, let’s focus on a simplified version of the index action, shown in Listing 2.4. (The scaffold code is ugly and confusing, so I’ve suppressed it.)  

 

  This index action has the line @users = User.all (Step 3), which asks the User model to retrieve a list of all the users from the database (Step 4), and then places them in the variable @users (pronounced ‘‘at-users’’) (Step 5). The User model itself appears in Listing 2.5; although it is rather plain, it comes equipped with a large amount of functionality because of inheritance (Section 2.3.4 and Section 4.4). In particular, by using the Rails library called Active Record, the codein Listing 2.5 arranges for User.all to return all the users. (We’ll learn about the attr_accessible line in Section 6.1.2. Note: This line will not appear if you are using Rails 3.2.2 or earlier.)

 
 
 
image
Neha  Jaggi

Skills    Ruby On Rails

Qualifications :- High School - , College/University - Graphic Era Hill University, Dehradun, College/University - ,
Location :-Dehradun,Dehradun,UTTARAKHAND,India
Description:-

Experienced Software Developer with a demonstrated history of working in the Information Technology and services industry. Skilled in Web Technologies (Ruby on Rails, PostgreSQL, php, Laravel and AJAX). 


Explore
 

  Students (0)