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.

Editing projects<br />

If you run bin/cucumber features/editing_projects.feature again, it now<br />

complains about the missing edit action:<br />

The action 'edit' could not be found for ProjectsController<br />

You should now define this action in your ProjectsController, underneath the show<br />

action, as in the following listing.<br />

Listing 4.7 app/controllers/projects_controller.rb<br />

def edit<br />

@project = Project.find(params[:id])<br />

end<br />

As you can see, this action works in an identical fashion to the show action, where the<br />

ID for the resource is automatically passed as params[:id]. Let’s work on DRYing 3 this<br />

up once you’re done with this controller. When you run feature again, you’re told that<br />

the edit view is missing:<br />

Given I am on the homepage<br />

Missing template projects/edit, application/edit<br />

with {:handlers=>[:erb, :builder],<br />

:formats=>[:html],<br />

:locale=>[:en, :en]}.<br />

Searched in:<br />

* ".../ticketee/app/views"<br />

It looks like you need to create this template. For this edit action’s template, you can<br />

re-use the form partial (app/views/projects/_form.html.erb) you created in chapter 3<br />

by putting the code from the following listing into app/views/projects/edit.html.erb.<br />

Listing 4.8 app/views/projects/edit.html.erb<br />

Edit project<br />

<br />

When you pass a string to the render method, Rails looks up a partial in the current<br />

directory matching the string and renders that instead. Using the partial, the next<br />

step passes without any further intervention from you when you run bin/cucumber<br />

features/editing_projects.feature, but the output now says it can’t find the<br />

update action:<br />

And I fill in "Name" with "TextMate 2 beta"<br />

And I press "Update Project"<br />

The action 'update' could not be found for ProjectsController<br />

Great! It looks like the edit action is working fine, so your next step is to define the<br />

update action.<br />

3 As a reminder: DRY = Don’t Repeat Yourself!<br />

89

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

Saved successfully!

Ooh no, something went wrong!