27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

14 CHAPTER 1 Ruby on Rails, the framework<br />

Great! Here, you’re told that Name can’t be blank and that the value you entered for<br />

Cost isn’t a number. Let’s see what happens if you enter foo for the Name field and<br />

-100 for the Cost field, and click Create Purchase. You should get a different error for<br />

the Cost field now, as shown in figure 1.6.<br />

Good to see! Both of your validations are working now. When you change Cost to<br />

100 and click Create Purchase, it should be considered valid by the validations and<br />

take you to the show action. Let’s look at what this particular action does now.<br />

1.2.8 Showing off<br />

This action displays the content such as shown in figure 1.7.<br />

The number at the end of the URL is the unique numerical ID for this purchase. But<br />

what does it mean? Let’s look at the view for this show action now, as shown in the following<br />

listing.<br />

Listing 1.8 app/views/purchases/show.html.erb<br />

<br />

<br />

Name:<br />

<br />

<br />

<br />

Cost:<br />

Figure 1.7 A single purchase<br />

Figure 1.6 Cost must<br />

be greater than 0

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!