28 May 2013, 07:32
Generic-user-small

Michael Hao Chen (1 post)

I know the current_cart method in the base class can find the target cart by session. However, i don’t know where the sysbol :card_id is from.

When the lineItemController calls the current_cart method, what is the value of :cart_id?

What’s is more, I have already run this common “rails generate scaffold line_item product_id:integer cart_id integer”. What is the relationship between these kinds of cart_id? class ApplicationController < ActionController::Base protect_from_forgery

private def current_cart Cart.find(session[:cart_id]) rescue ActiveRecord::RecordNotFound cart = Cart.create session[:cart_id] = cart.id cart end end

30 May 2013, 00:55
Samr_small_pragsmall

Sam Ruby (584 posts)

In section 4.1 there is a brief introduction to Ruby names. :cart_id is an example of a Ruby symbol, which is roughly a constant string. There is no limit to the number of symbols you may have in an application, nor do symbols need to be declared.

I hope this helps.

  You must be logged in to comment