27.02.2013 Views

Rails%203%20In%20Action

Rails%203%20In%20Action

Rails%203%20In%20Action

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

212 CHAPTER 8 More authorization<br />

45 scenarios (45 passed)<br />

451 steps (451 passed)<br />

# and<br />

26 examples, 0 failures, 11 pending<br />

Everything’s still green, which means it’s time for another commit:<br />

git add .<br />

git commit -m "Added a seeds file"<br />

git push<br />

Now you’re done!<br />

8.10 Summary<br />

This chapter covered implementing authorization for your application and setting up<br />

a permissions-based system for both the ProjectsController and TicketsController.<br />

You started with a Permission model, which you used in a scope on the Project<br />

model to show only the projects a user should be able to access. Then you used the<br />

CanCan plugin, which provided the can? and cannot? methods to use first in the controllers<br />

to stop users from accessing specified actions and then in the views, through<br />

the authorized? method, to stop users from seeing specified links.<br />

You implemented a way for admins to change the permissions of a user through<br />

the admin backend of the system by displaying a series of check boxes. Here you used<br />

an update action that wasn’t quite like the normal update action, and you had to<br />

define a custom-named route for it.<br />

Finally, you learned how to set up seed data for your application so you have a solid<br />

base of objects to work from. Without using seed data, you’d have to manually set up<br />

the data not only for your local development environment but also for your production<br />

server, which can be tedious. Seed data saves you that effort. You also wrote a test<br />

for this data in the form of a feature that ensures the data from the seed file is always<br />

created when the seed task is run.<br />

In chapter 9, you learn how to attach files to tickets. File uploading is an essential<br />

part of any ticket-tracking application because files can provide that additional piece of<br />

context required for a ticket, such as a screenshot, a patch, or any type of file. You also<br />

learn about restricting the availability of these files on the basis of users’ permissions.

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

Saved successfully!

Ooh no, something went wrong!