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.

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

You can create the file app/views/projects/show.html.erb with the following content<br />

for now:<br />

<br />

When you run rake cucumber:ok, you see this message:<br />

And I press "Create Project"<br />

Then I should see "Project has been created."<br />

expected #has_content?("Project has been created.")<br />

to return true, got false<br />

This error message shows the has_content? method from Capybara, which is used to<br />

see if the page has specific content on it. It’s checking for "Project has been<br />

created." and is not finding it. Therefore, you must put it somewhere, but where?<br />

The best location is in the application layout, located at app/views/layouts/<br />

application.html.erb. This file provides the layout for all templates in your application,<br />

so it’s a great spot for the flash message.<br />

Here is quite the interesting file:<br />

<br />

<br />

Ticketee<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

<br />

The first line sets up the doctype to be HTML for the layout, and three new methods<br />

are used: stylesheet_link_tag, javascript_include_tag, and csrf_meta_tags.<br />

stylesheet_link_tag is for including stylesheets from the app/assets/stylesheets<br />

directory. Using this tag results in the following output:<br />

<br />

The /assets path is served by a gem called sprockets. In this case, you’re specifying<br />

the /assets/application.css path, so Sprockets looks for a file called app/assets/application.css,<br />

which would usually act as a manifest file listing the Cascading Style Sheets<br />

(CSS) files that need to be included for the application. The current manifest file just<br />

provides a stylesheet for the entire application.<br />

For your CSS files, you can use the Sass language to produce more powerful<br />

stylesheets. Your application depends on the sass-rails gem, which itself depends on

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

Saved successfully!

Ooh no, something went wrong!