Ruby On Rails Classroom image

Neha  Jaggi / Professional / Web Technology

To post your Question Join Classroom
Lesson Topics's No:-  |1 | 2 | 3 | 4|Last
Lessons:- Signup Failure

  Signup Failure

Although we’ve briefly examined the HTML for the form in Figure 7.12 (shown in Listing 7.20), it’s best understood in the context of signup failure. In this section, we’ll create a signup form that accepts an invalid submission and re-renders the signup page with a list of errors, as mocked up in Figure 7.14.


  A Working Form

Our first step is to eliminate the error that currently results when submitting the signup form, as you can verify in your browser or by running the test for signup with invalid information:


$  bundle  exec  rspec spec/requests/user pages spec.rb \
-e "signup with invalid information"



Recall from Section 7.1.2 that adding resources :users to the routes.rb file (Listing 7.3) automatically ensures that our Rails application responds to the RESTful URIs from Table 7.1. In particular, it ensures that a POST request to /users is handled by the create action. Our strategy for the create action is to use the form submission to make a new user object using, try (and fail) to save that user, then render the signup page for possible resubmission. Let’s get started by reviewing the code for the signup form:

<form   action=  "/users"  class=  "new user"  id=  "new user" method=  "post" >


 As noted in Section 7.2.3, this HTML issues a POST request to the /users URI. We can get the test for invalid information from Listing 7.16 to pass with the
code in Listing 7.21. This listing includes a second use of the render method, which we first saw in the context of partials (Section 5.1.3); as you can see, render works in controller actions as well. Note that we’ve taken this opportunity to introduce an if-else branching structure, which allows us to handle the cases of failure and success separately based on the value of, which (as we saw in Section 6.1.3) is either true or false depending on whether the save succeeds.

Neha  Jaggi

Skills    Ruby On Rails

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

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). 


  Students (0)