S Ruby D Thomas and D H Hansson Agile Web Development with Rails 32 Pragmatic

S ruby d thomas and d h hansson agile web development

This preview shows page 168 - 170 out of 517 pages.

S. Ruby, D. Thomas, and D. H. Hansson. Agile Web Development with Rails 3.2 (Pragmatic Programmers) . Pragmatic Bookshelf, 2011. ISBN 1934356549. 4.12 Suggested Projects Unless otherwise indicated, these suggested projects are based on the myrottenpotatoes app you created in this chapter. Project 4.1. Add a default banner to the main application layout that will appear on every page of RottenPotatoes. It should display “RottenPotatoes” in large red letters, but no visual styling information should go into the template itself. (Hint: pick an element type that reflects the role of this banner, assign it a unique ID, and modify the CSS style file to style the element.) Make it so that clicking on the banner always takes you to RP homepage. Project 4.2. Instead of redirecting to the Index action after a successful create , redirect to the show action for the new movie that was just created. Hint: you can use the movie_path URI helper but you’ll need to supply an argument identifying which movie. To obtain this argument, recall that Movie.create if successful returns the newly-created object in addition to creating it. Project 4.3. Modify the listing of movies as follows. Each modification task will require making a change at a different layer of abstraction: 1. Modify the Index view to include a row number for each row in the movies table. HINT: look up the documentation of the each_with_index function used in line 11 of the view template. 2. Modify the Index view so that hovering a mouse over a row in the movies table causes the row to temporarily assume a yellow background. HINT: look up the hover pseudo-class supported by CSS.
Image of page 168
3. Modify the Index controller action to return the movies ordered alphabetically by title, rather than by release date. HINT: Don’t try to sort the result of the controller’s call to the database. RDBMS’s provide ways to specify the order in which a list of results is delivered, and because of Active Record’s tight coupling to the underlying RDBMS, the Rails ActiveRecord library’s find and all methods provide a way to ask the underlying RDBMS to do this. 4. Pretend you didn’t have the tight coupling of Active Record, and so you could not assume the underlying storage system can return collection items in any particular order. Modify the Index controller action to return the movies ordered alphabetically by title. HINT: Look up the sort method in Ruby’s Enumerable module. Project 4.4. What if the user changes his mind before submitting a Create or Update form and decides not to proceed after all? Add a “Cancel” link to the form that just takes the user back to the list of movies. Project 4.5. Modify the “Cancel” link so that if it’s clicked as part of a Create flow, the user is taken back to the list of movies, but if clicked as part of an Update flow, the user is taken back to the Show template (view) for the movie he began to edit. Hint: the instance method ActiveRecord::Base#new_record?
Image of page 169
Image of page 170

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