Task F: Administration

Attempting to delete the last user at end of AWDWR2 11.4 results in a runtime exception raised instead of the expected flash banner display. The solution is to modify the LoginController#delete_user routine described on page 161 to match the one in the full listing on page 661. Add the begin/end blocks with a rescue clause to set the flash. This is mentioned near the bottom of page 163 but the code was not described at that point. This was in the first edition but the rescue block was lost from the second edition.


Modify the user update function to accept a confirmed password instead of a hashed password and a salt. Discuss


Adapt the checkout code from the previous chapter to use a single action, rather than two. Discuss


When the system is freshly installed on a new machine, there are no administrators defined in the database, and hence no administrator can log on. But, if no administrator can log on, then no one can create an administrative user. Change the code so that if no administrator is defined in the database, any user name works to log on (allowing you to quickly create a real administrator). Discuss


Experiment with script/console. Try creating products, orders, and line items. Watch for the return value when you save a model object—when validation fails, you’ll see false returned. Find out why by examining the errors. Discuss

  >> prd = Product.new 
  => #<Product:0x271c25c @new_record=true, @attributes={"image_url"=>nil, 
        "price"=>#<BigDecimal:2719a48,'0.0',4(8)>, "title"=>nil, 
        "description"=>nil}> 
  >> prd.save 
  => false 
  >> prd.errors.full_messages 
  => ["Image url must be a URL for a GIF, JPG, or PNG image", 
         "Image url can't be blank", "Price should be at least 0.01", 
         "Title can't be blank", "Description can't be blank"]
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License