introduced in Section 32 yields an object

Introduced in section 32 yields an object

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

introduced in Section 3.2 ). ActionController::MimeResponds#respond_to yields an object that can be used to select the format in which to render a response. Here’s how the update action can be immediately converted into an SOA-friendly RESTful API that updates a movie’s attributes and returns an XML representation of the updated object, while preserving the existing user interface for human users: 1 def update 2 @movie = Movie.find params[:id] 3 @movie.update_attributes!(params[:movie]) 4 respond_to do |client_wants| 5 client_wants.html { redirect_to movie_path(@movie) } # as before 6 client_wants.xml { render :xml => @movie.to_xml } 7 end 8 end Similarly, the only reason new requires its own controller action is that the human user needs an opportunity to fill in the values that will be used for create . Another service would never call the new action at all. Nor would it make sense to redirect back to the list of movies after a create action: the create method could just return an XML representation of the created object, or even the created object’s ID. Thus, as with many tools we will use in this book, the initial learning curve to do a simple task may seem a bit steep, but you will quickly reap the rewards by using this strong foundation to add new functionality and features quickly and concisely. 4.11 To Learn More The online documentation for Rails gives details on the language, its classes, and the Rails framework.
Image of page 167
The Ruby Way ( Fulton 2006 ) and The Rails 3 Way ( Fernandez 2010 ) go into great depth on Ruby and Rails advanced features and wizardry. Agile Web Development With Rails, 4th edition Ruby et al. 2011 is co-authored by David Heinemeier Hansson, the creator of Rails, and is a tutorial-oriented introduction that combines Ruby and Rails, although its emphasis on testing and BDD is less than we would like. You can get it from major retailers or directly from the publisher , where you can get a discount for purchasing the print book and (multi-format) ebook together. PluralSight publishes high-quality screencasts covering almost every tool and technique in the Rails ecosystem for a very reasonable price (in the authors’ opinion). The five-part Introduction to Rails 3 screencast is a particularly good complement to the information in this chapter. Before writing new code for any functionality that isn’t specific to your app, check rubygems and rubyforge (at least) to see if someone has created a gem that does most of what you need. As we saw in this chapter, using a gem is as easy as adding a line to your Gemfile and re-running bundle install . O. Fernandez. Rails 3 Way, The (2nd Edition) (Addison-Wesley Professional Ruby Series) . Addison- Wesley Professional, 2010. ISBN 0321601661. H. Fulton. The Ruby Way, Second Edition: Solutions and Techniques in Ruby Programming (2nd Edition) . Addison-Wesley Professional, 2006. ISBN 0672328844.
Image of page 168
Image of page 169

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