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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:20:45+00:00 2026-06-12T04:20:45+00:00

Coming from Java, a highly explicit language, to RoR, which uses a very terse

  • 0

Coming from Java, a highly explicit language, to RoR, which uses a very terse syntax, is easy for the most part, but I’m struggling to understand a few of the things that are going on behind the scenes.

In the code below, how does Rails assign product_id: a value? Couldn’t product.id be used instead? What does the product_id: mean exactly in this context? Where does its value come from?

In the view:

<% @products.each do |product| %>
<div class="entry">
<%= image_tag(product.image_url) %>
<h3><%= product.title %></h3>
<%= sanitize(product.description) %>
<div class="price_line">
  <span class="price"><%= number_to_currency(product.price, unit: '$') %></span>
  <%= button_to 'Add to Cart', line_items_path(product_id: product) %>
</div>
</div>
<% end %>

Is it because of the attr_accessible statements I gave in my line_items model?:

class LineItem < ActiveRecord::Base
  attr_accessible :cart_id, :product_id
  belongs_to :product
  belongs_to :cart
end
  • 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-12T04:20:46+00:00Added an answer on June 12, 2026 at 4:20 am

    Actually, belongs_to :product is what gives your model (LineItem) this attribute. So now you can reference the parent product (that this LineItem belongs to), by doing for example LineItem.find(1).product_id, which would return the same as doing LineItem.find(1).product.id.

    Rails uses this conventional attribute (product_id) as it directly maps to the table column. Check your schema.rb file, you will find it there, inside the line_items table.

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

Sidebar

Related Questions

Coming from OO (C#, Java, Scala) I value very highly the principles of both
I'm currently learning the C programming language (coming from Java) and I'm a bit
Coming from LISP I am having my most challenging moments when accessing java objects.
Coming from Java , I'm used to the package structure (com.domain.appname.tier) Now I've started
I am coming from Java to Ruby and this -7 mod 3 = 2
Background: I'm coming from Java background so not too familiar with Javascript. We are
new to Laravel (coming from Java spring), while using Route::get('/', function() { return Hello
I'm coming from Java/C++ to Ada and am having trouble figuring out the small
I'm coming from Java, where I'd submit Runnable s to an ExecutorService backed by
I am coming from Java and try to learn Javascript right now. Doing that

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.