Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9174543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:46:18+00:00 2026-06-17T16:46:18+00:00

I am looking at a rails example for shopping carts and in the ApplicationController

  • 0

I am looking at a rails example for shopping carts and in the ApplicationController class I see code like this:

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

so it is using a Cart.find(session[:cart_id])

Then I go to carts_controller.rb and CartController class and I see code like this:

 def update
    @cart = Cart.find(params[:id])

    respond_to do |format|

so here it is using Cart.find(params[:id])

But I can’t understand why we used session to pass params in the AppController but we used normal params in the CartController and could we use swithc use of them ? or is it how rails works and always session goes to AppController? Would be greta if someone can explain this in more details

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T16:46:20+00:00Added an answer on June 17, 2026 at 4:46 pm

    params live in the url or in the post body of a form, so it vanishes as soon as the query is made.

    Session persists between multiple requests (the info are often stored in cookies but this depends on your configuration).

    To be short:

    • params: one request only (creation of one object, access to one particular page)
    • session: info to be persisted (cart, logged user..)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Looking at the example of form_for from the rails docs , I see this
I was looking at example code from the O'Reilly book on Ruby on Rails
I am looking for a Rendezvous like design pattern example or implementation in Rails?
I'm trying to learn Rails better by looking at example applications, and while looking
Looking for a Rails validation that will only allow letters, numbers, and spaces. This
Is there any open source (or example) code for Ruby on Rails which can
I am only looking for answers from senior/more experienced Ruby/Rails developers on this one,
I mainly worked with Rails-like frameworks in the past. Recently, I've been looking into
I'm looking for a good example repository of a Rails 3 project that implements
Iam looking for a Django or Rails example with Google login+Facebook+Twitter. My goal is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.