Search engine crawlers explore the Web by following GET links Imagine Google

Search engine crawlers explore the web by following

This preview shows page 165 - 167 out of 517 pages.

Search engine crawlers explore the Web by following GET links. Imagine Google triggering millions of spurious purchases every time it crawled an e-commerce site! Since deleting something is not a “safe” operation, Rails handles deletion using a POST . As the Elaboration at the end of Section 6.5 explains, the unusual HTML generated by link_to , when combined with JavaScript, actually results in a form being created and POST ed when the link is clicked —thereby alowing JavaScript-enabled browsers to safely handle the destructive delete operation. Try modifying the index view (list of all movies) so that each table row displaying a movie title also includes an Edit link that brings up the edit form for that movie and a Destroy button that deletes that movie with a confirmation dialog. Self-Check 4.8.1. Why does the form in new.html.haml submit to the create method rather than the new method? As we saw in Chapter 2 , creating a new record requires two interactions. The first one, new , loads the form. The second one, create , submits the form and causes the actual creation of the new record. Self-Check 4.8.2. Why does it make no sense to have both a render and a redirect (or two renders, or two redirects) along the same code path in a controller action? Render and redirect are two different ways to reply to a request. Each request needs exactly one reply. Summary Rails provides various helpers for creating HTML forms that refer to ActiveRecord models. In the controller method that receives the form submission, the keys in the params hash are the form fields’ name attributes and the corresponding values are the user-selected choices for those fields. Creating and updating an object are resources whose visible representation is just the success or
Image of page 165
failure status of the request. For user friendliness, rather than displaying a web page with just success or failure and requiring the user to click to continue, we can instead redirect_to a more useful page such as index . Redirection is an alternative way for a controller action to finish, rather than rendering a view. For user friendliness, it’s typical to modify the application layout to display messages stored in flash[:notice] or flash[:warning] , which persist until the next request so they can be used with redirect_to . To specify the URIs required by both form submissions and redirections, we can use RESTFUL URI helpers like movies_path and edit_movie_path rather than creating the URIs manually. 4.9 Fallacies and Pitfalls Pitfall: Modifying the database manually rather than using migrations, or managing gems manually rather than using Bundler. Especially if you’ve come from other SaaS frameworks, it may be tempting to use the SQLite3 command line or a GUI database console to manually add or change database tables or to install libraries. But if you do this, you’ll have no consistent way to reproduce these steps in the future (for example at deployment time) and no way to roll back the changes in an orderly way. Also, since
Image of page 166
Image of page 167

You've reached the end of your free preview.

Want to read all 517 pages?

  • Spring '19
  • Dr.Marcos

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors