Change the application so that clicking a book’s image will also invoke the create action.
Hint: the first parameter to
link_to is placed in the generated
<a> tag, and the Rails helper
image_tag constructs an HTML
<img> tag. Include a call to it as the first parameter to a
link_to call. Be sure to include
:method => :post in your
html_options on your call to
Add a new variable to the session to record how many times the user has accessed the
Hint: The first time through, your count won’t be in the session. You can test for this with code like
if session[:counter].nil? ...
If the session variable isn’t there, you’ll need to initialize it. Then you’ll be able to increment it.
Pass this counter to your template, and display it at the top of the catalog page.
Hint: the pluralize helper might be useful when forming the message you display.
Reset the counter to zero whenever the user adds something to the cart.
Hint: adding something to a cart doesn’t modify the Cart, instead look to add this logic to the
<code>create</code> method of the <code>line_items_controller</code>.
h4. Activity 5
Change the template to display the counter only if it is greater than five.
*Hint*: While this _can_ be done inside the template, it _should_ be done in the controller.
It will be more fun to put the counter message in the error display area using flash. The requirements are: if there is no error, just display the counter; but if there is an error, then display the error and the counter. When the index page is refreshed, remove the error and update the counter.
*Hint*: use a session variable to keep track of whether there is a redirect.