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 9318963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T03:15:55+00:00 2026-06-19T03:15:55+00:00

I don’t understand 5th line in line_items_controller.rb : I notice the code for Rails

  • 0

I don’t understand 5th line in “line_items_controller.rb” :
I notice the code for Rails 3.1 don’t have such line while in code for Rails 3.2 it has such line.
From Java world, It’s hard to tell what kind of magic ruby used here 🙁
I was stuck in understanding Rails document.

e.g.
button_to has signiture button_to(name, options = {}, html_options = {})

But in the code, you can add on parameter like

<%= button_to 'Empty cart', @cart, :method => :delete, :confirm => 'Are you sure?' %>

I suppose @cart shouldn’t be there…

def create
    @cart = current_cart #this is a function method
    product = Product.find(params[:product_id])
    @line_item = @cart.add_product(product.id)
    @line_item.product = product

    respond_to do |format|
      if @line_item.save
        format.html { redirect_to @line_item.cart }
        format.json { render json: @line_item,
          status: :created, location: @line_item }
      else
        format.html { render action: "new" }
        format.json { render json: @line_item.errors,
          status: :unprocessable_entity }
      end
    end
end

Full source code for project here:
https://github.com/ilovejs/depot_i/blob/master/app/controllers/line_items_controller.rb

  • 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-19T03:15:56+00:00Added an answer on June 19, 2026 at 3:15 am

    it seems like @cart.add_product(product.id)if to add a product to the @cart, and @line_item.product = product is also seems like doing the same thing

    its little hard to tell without seeing the code of Cart model, however I think

    removing the @line_item.product = product line should also work without a problem

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't they both have to convert to machine code at some point to execute
Don't know if this is possible, but I have some code like this: val
Don't understand this simple code: def main(): print (This program illustrates a chaotic function)
Don't know if this has been answered before. Have custom routes to users. If
Don't understand, if Data.Map is and [] is. I found this out while wondering
Don't understand why #include <Header.h> is not compiling while #include Header.h is compiling with
don't know better title for this, but here's my code. I have class user
Don't ask me how but I'm in a situation where I have DCPs published
Don't be scared of the extensive code. The problem is general. I just provided
Don't know how to google for such, but is there a way to query

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.