Home arrow Ruby-on-Rails arrow Completing Tagging Support

Completing Tagging Support

In this conclusion to a four-part series on adding tagging support to an ecommerce website with Ruby on Rails, you'll learn how to enable tag editing, and allow site visitors to view tags, among other things. This article is excerpted from chapter seven of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 1
June 11, 2010
  1. · Completing Tagging Support
  2. · Modifying the Controller
  3. · Implementing the List Tags and Show Tag User Stories
  4. · Implementing the Recommend Books User Story

print this article

Completing Tagging Support
(Page 1 of 4 )

Implementing the Edit Tags User Story

George must be able to go back to a book that he has added to the system and edit the details, including removing and adding tags. The edit book page uses the same_form.rhtml partial as we used for the add book page. This means that most of the work has already been done in the previous section. The only part of the code we need to change is the controller. As usual, we will start by creating the integration test.

Updating the Integration Test

Change thetest_book_administrationmethod in the integration testtest/integration/ book_test.rb. Add thetagsparameters to the line that starts withgeorge.edit_book, as shown here:

  george.edit_book(ruby_for_dummies, :tags => 'Toddlers', :book => {
    :title => 'Ruby for Toddlers',
    :publisher_id => publisher.id,
    :author_ids => [author.id],
    :published_at => Time.now,
    :isbn => '123-123-123-X',
    :blurb => 'The best book released since "Eating for Toddlers"',
    :page_count => 123,
    :price => 40.4

Also change the implementation ofedit_bookDSL method as follows:

def edit_book(book, parameters)
  get "/admin/book/edit/#{book.id}"
  assert_response :success
  assert_template "admin/book/edit"

  post "/admin/book/update/#{book.id}", parameters
  assert_response :redirect
  assert_response :success
  assert_template "admin/book/show"

  assert_equal parameters[:tags].split(',').size, book.tags.size

Note that we reload thebookobject from the database, before we check that the tags have been updated.

Run the test, and you should see it fail with the following error message:

<1> expected but was

You get the error because we havenít yet modified the controller.

blog comments powered by Disqus

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials