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.

282 CHAPTER 10 Tracking state<br />

10.5.3 Hacking a form<br />

Even if your state field is hidden from view, users are still able to submit a form<br />

containing this parameter, and your application will accept it. Let’s now see this in<br />

practice.<br />

The first things you need to do are to create a user and give it read access to a<br />

project, which you can do by starting rails console (or rails c) and running these<br />

commands:<br />

user = Factory(:user)<br />

user.confirm!<br />

user.permissions.create(:object => Project.first,<br />

:action => "view")<br />

Let’s quit the console by typing exit and then start up the application with rails<br />

server. Now you can sign in with the user@ticketee.com email and password password.<br />

Once you’re in, you should see the page shown in figure 10.16.<br />

Let’s go into this project and pick any<br />

ticket in the list or create your own. It<br />

doesn’t matter, you just need a ticket. When<br />

you’re on the ticket page, save this page by<br />

choosing File and then Save or Save Page As,<br />

and save this file in a memorable location.<br />

You’re going to be editing this saved file and<br />

adding a State select box of your own.<br />

Open this saved file in a text editor, and Figure 10.16 What the user sees<br />

look for the following lines:<br />

<br />

Text<br />

<br />

<br />

These lines display the Text label and the associated textarea for a new comment.<br />

You’re able to add the state field underneath the text field by adding this code 5 to<br />

the page:<br />

<br />

State<br />

<br />

New<br />

Open<br />

Closed<br />

<br />

<br />

When you save this page, you’ll now be able to choose a state when you open it in a<br />

browser. The action of the form tag on this page goes to http://localhost:3000/tickets<br />

5 Assuming you know the IDs of the states.

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

Saved successfully!

Ooh no, something went wrong!