15 Oct 2013, 03:01

Luis Varela (2 posts)

I`am new on Rails, and I love it!!

I use Ubuntu 12.10

I Install Rails 3.2.0

Ruby 1.9

I follow the manual “Agile Web Development with Rails” 3.2.

But I`am in trouble anyway… ¿maby a bad configuration of my URLs? mmmmmm…..

In the page 92 they say delete the public/index.html.erb and to root the “store” page to the local host… in /config/routes.rb like this.

Plore::Application.routes.draw do

resources :products

resources :store

get “store/index”

root to: ‘store#index’, as: ‘store’

This takes me to de local host anyways… “Welcome Aboard” Grrrrrr…..

No problem, I keep advancing with the old way…

But in page 112 I finish with all the sutups, and I click the button to “Add to Cart” and instead of the red message “line item was successfully created” I get a crash and I just can`t fix it.

In the console of “rails server” I get this messages…

Started POST “/line_items?product_id=5” for at 2013-10-14 23:29:10 -0400

Processing by LineItemsController#create as HTML

Parameters: {“authenticity_token”=>”kF32kEdm2++nfKJPNN2o4rAgw/8ED0KJ4FlVeCDWAM4=”, “product_id”=>”5”}

(0.1ms) begin transaction

SQL (2.1ms) INSERT INTO “carts” (“created_at”, “updated_at”) VALUES (?, ?) [[“created_at”, Tue, 15 Oct 2013 03:29:10 UTC +00:00], [“updated_at”, Tue, 15 Oct 2013 03:29:10 UTC +00:00]]

(306.0ms) commit transaction

Product Load (0.3ms) SELECT “products”.* FROM “products” WHERE “products”.”id” = ? LIMIT 1 [[“id”, “5”]]

Completed 500 Internal Server Error in 330ms

NoMethodError (undefined method `line_items’ for #):

app/controllers/line_items_controller.rb:45:in `create’

Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.2ms)

Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (1.3ms)

Rendered /usr/local/rvm/gems/ruby-1.9.3-p448/gems/actionpack-3.2.0/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (5.6ms)

In the web I get this:

NoMethodError in LineItemsController#create

undefined method `line_items’ for #

Rails.root: /home/lmbv/Dropbox/rails/plore

Application Trace Framework Trace Full Trace

app/controllers/line_items_controller.rb:45:in `create’ Request


{“authenticity_token”=>”kF32kEdm2++nfKJPNN2o4rAgw/8ED0KJ4FlVeCDWAM4=”, “product_id”=>”5”}

Any Help…?

My greatest gratitude if one of you can see this…

22 Oct 2013, 12:52

Luis Varela (2 posts)

Well I fix my problem!!

In the first place I fix my URL problem with ( rake routes ) that in the manual it`s not mentioned in Chapter 8.

rake routes

In the other hand, the main error I fix it following the instructions of Sam Ruby, of this forum. My regards to you. He rout…

Ken, please verify that app/models/cart.rb has the following line:

has_many :line_items

Goodbye to all!!

  You must be logged in to comment