I came across a demo with the following line:
map.current_cart 'cart', :controller => 'carts', :action => 'show', :id => 'current'
Does setting the id to 'current' call the function current_cart by some magic?
application_controller.rb:
def current_cart
session[:cart_id] ||= Cart.create!.id
@current_cart ||= Cart.find(session[:cart_id])
end
See carts_controller. Method
current_cartcalls from actionshow. So there is not any magic: it is just calling method from action and it do the next steps:@current_cart. It will also available in any view@cartvariable in show action forcarts_controller