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.

450 CHAPTER 16 Basic performance enhancements<br />

This time, rather than simply processing your action and sending the response body<br />

back to the server, Rails will save the body in a new file in your application at public/<br />

projects/1.html. The next time this route is requested, because the public/projects/<br />

1.html page exists, it will be served by your web server, rather than Rails. A side-effect<br />

of this means that your request will not show up in the Rails console, but at least it will<br />

be served faster.<br />

Let’s reload the page now; it should be a little faster because it’s serving that static<br />

page. If you click the Next link on your pagination, you’ll still be shown the first page.<br />

This is because the GET parameter was ignored, and the first page for this project’s<br />

tickets was what was cached.<br />

There’s another problem too: this result is cached for all users of your application.<br />

At the top of the page, you’ll be able to see the message that says “Signed in as<br />

admin@ticketee.com,” as shown in figure 16.6.<br />

To see this little issue in action, sign up as another user by first clicking the Sign<br />

Out link in the application to sign out, then the Sign Up link to be presented with a<br />

form to sign up. In this form, enter user@ticketee.com for the email and password<br />

for both the password and password confirmation fields. When you click the Sign Up<br />

button, this will create your new user account.<br />

You currently require users to confirm their account through an email they<br />

receive, but because you’re in development mode there will be no emails sent. To confirm<br />

this user, launch rails console now and run these commands:<br />

user = User.find_by_email("user@ticketee.com")<br />

user.confirm!<br />

You’ll also need to give this user access to the first project in your system, so that they<br />

can view the tickets too. To do this, run these couple of commands:<br />

project = Project.first<br />

user.permissions.create!(:action => "view", :thing => project)<br />

Alright, now that your user is confirmed and has access to this project, let’s see what<br />

happens when you sign in with the email and password you used to sign up,<br />

user@ticketee.com and password. At the top of the page you’ll see that you’re signed<br />

in as the new user, as seen in figure 16.7.<br />

Figure 16.6 Signed in as admin Figure 16.7 Signed in as a user

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

Saved successfully!

Ooh no, something went wrong!