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.

60 CHAPTER 3 Developing a real Rails application<br />

ProjectsController, you could put an action’s template at app/views/application,<br />

app/views/projects, or app/views/that_controller, and Rails would still pick up on it.<br />

This allows different controllers to share views in a simple fashion.<br />

To generate this view, create the app/views/projects/index.html.erb file for now.<br />

When you run rake cucumber:ok again, you get back to what looks like the original<br />

error:<br />

Given I am on the homepage<br />

When I follow "New Project"<br />

no link with title, id or text 'New Project' found<br />

Although this looks like the original error, it’s actually your first step truly passing now.<br />

You’ve defined a homepage for your application by generating a controller, putting an<br />

action in it, and creating a view for that action. Now Cucumber (via Capybara) can<br />

navigate to it. That’s the first step in the first feature passing for your first application,<br />

and it’s a great first step!<br />

The second step in your features/creating_projects.feature file is now failing, and<br />

it’s up to you to fix it. You need a link on the root page of your application that reads<br />

"New Project". Open app/views/projects/index.html.erb, and put the link in by using<br />

the link_to method:<br />

<br />

This single line re-introduces two old concepts and one new one: ERB output tags, the<br />

link_to method (both of which you saw in chapter 1), and the mysterious<br />

new_project_path method.<br />

As a refresher, in ERB, when you use

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

Saved successfully!

Ooh no, something went wrong!