O'Reilly logo

Learning Rails: Live Edition by Edd Dumbill, Simon St. Laurent

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Test Your Knowledge

Quiz

  1. What is the difference between <% and <%=?

  2. How much logic should you put in your ERb files?

  3. How does Rails know what controller goes with what view, if you don’t tell it?

  4. Which methods should you use to protect yourself against potential insertions of unwanted HTML?

Answers

  1. When you use <%=, Rails will insert the return value of the code you’ve used into the document. If you use <%, nothing will be added to the document.

  2. In general, you should put as little logic into your ERb files as possible. You may need to put some logic there to make sure that users get the right presentation of the information you’re sharing, or to build an interface for them to work with it. However, you should avoid putting much else there.

  3. Rails maps controllers to views through naming conventions, unless your code specifies otherwise.

  4. The h method and the sanitize method will remove most potentially dangerous markup.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required