Going Back in Rails 5

In this article, we will see the changes required to get the original railscasts Going Back to work on Rails 5. Create the models.

rails g model product name category:references price:decimal description:text
rails g model category name
rails g model cart token
rails g model cart_item product:references cart:references quantity:integer

Change the migration for create_cart_times:

t.integer :quantity, default: 1 

Since we make the quantity default to one, we can delete the following private method:

private

def default_quantity_to_one
  self.quantity ||= 1
end

in cart_item model. Generate the controllers.

rails g controller cart_items create
rails g controller carts show
rails g controller categories
rails g controller products

You can download the source code for this article from https://github.com/bparanj/sto.re. Note: Remember to delete session[:last_product_page] once the checkout is complete.


Related Articles


Create your own user feedback survey