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.

Summary<br />

This scenario passes because of the changes you made to the controller and application<br />

layout, where you display all the flash messages. Of course, the third step is now<br />

failing. To display error messages in the view, you need to install the dynamic_form<br />

gem. To install it, add this line to your Gemfile underneath the line for the coffeerails<br />

gem:<br />

gem 'coffee-rails'<br />

gem 'dynamic_form'<br />

Then you must run bundle install to install it. Alternatively, you could install it as a<br />

plugin by using this command:<br />

rails plugin install git://github.com/rails/dynamic_form.git<br />

This command executes a git clone on the URL passed in and creates a new folder<br />

called vendor/plugins/dynamic_form in your application, putting the plugin’s code<br />

inside of it. Installing it as a plugin would lead to a “polluted” repository, so installing<br />

it as a gem is definitely preferred here. Also, when it’s installed as a gem, RubyGems<br />

and Bundler provide an exceptionally easy way of keeping it up to date, whereas the<br />

plugin architecture in Rails doesn’t. This is a good reason to try to use gems instead of<br />

plugins.<br />

The helpful method you’re installing this gem for is the error_messages method<br />

on the FormBuilder object—that is, what f represents when you use form_for in your<br />

app/views/projects/_form.html.erb view:<br />

<br />

Directly under this form_for line, on a new line, insert the following to display the<br />

error messages for your object inside the form:<br />

<br />

Error messages for the object represented by your form, the @project object, will now<br />

be displayed. When you run rake cucumber:ok, you get this output:<br />

2 scenarios (2 passed)<br />

12 steps (12 passed)<br />

Commit and push, and then you’re done with this story!<br />

git add .<br />

git commit -m "Add validation to ensure names are<br />

specified when creating projects"<br />

git push<br />

3.3 Summary<br />

We first covered how to version-control an application, which is a critical part of the<br />

application development cycle. Without proper version control, you’re liable to lose<br />

valuable work or be unable to roll back to a known working stage. We used Git and<br />

GitHub as examples, but you may use alternatives, such as SVN or Mercurial, if you<br />

prefer. This book covers only Git, because covering everything would result in a multivolume<br />

series, which is difficult to transport.<br />

81

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

Saved successfully!

Ooh no, something went wrong!