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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:39:06+00:00 2026-06-17T12:39:06+00:00

So I have the classes: Products, Carts, and LineItems – standard relationship (products and

  • 0

So I have the classes: Products, Carts, and LineItems – standard relationship (products and harts have many line items, and vice versa) and I one of the properties of the line items is size. When you show the Product in more detail, there is a form asking you to select the size, the form looks like this (there are arbitrary values in the select box)

<%=  form_for(:line_item, :url => {:controller => "line_items", :action => 'create', product_id: @product.id }) do |f| %>
<ul>
    <li>Size: <%= f.select(:size, 0..99) %></li>
    <li><%= link_to 'Add to Cart', line_items_path(product_id: @product.id), :method => :post %></li> <!-- This comes up later in the question -->
    <li><%= submit_tag "Add to Cart" %></li> <!-- using this Add to Cart button for now -->
</ul>
<% end %>

My first question is to resolve a problem. In the create definition of line_items I have the following two lines, and the problem is is that regardless of the size chosen, it records it as 1. Even if I choose 0, even if I choose 99. So what is my flaw in logic here? I’m sure I’m making a pretty big mistake, I just don’t know enough of what I’m doing wrong to properly search for the answer

@temp_size = params[:line_item]
@line_item.size = @temp_size.size

And my second question is that I would like to have a link as opposed to a button – I would prefer to be able to do this with a link like the 4th line in my form (middle list item) – are there properties I could use to replace the submit button?

Thanks!

  • 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-17T12:39:07+00:00Added an answer on June 17, 2026 at 12:39 pm

    First question:

    params[:line_item] is a hash containing data from the input fields of the submitted form.

    @temp_size.size is calling Hash#size which returns a count of key-value pairs in the hash. Since your form has only one input field, :size, @temp_size.size will always return 1 regardless of it’s value.

    To assign the value of the :size input field, do this:

    @temp_size = params[:line_item][:size] 
    

    Second question:

    You can use CSS to change the appearance of the submit button. You could also use a Javascript click handler to submit the form when a link is clicked. This should be it’s own question.

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

Sidebar

Related Questions

I have two classes in a many-to-many relationship, but only one of them have
I have a many-to-one relationship between objects Product and Supplier . I need to
In my model I have two classes Categories and Products. There is a relation
In my line of business we have Products. These products can be modified by
Suppose I have different sort of products on my site, so I have classes
I've got to classes Product and Store which have many to many relation I
I have two classes. One is Order: public class Order { public virtual int
I have two classes that each implement an interface. One of the classes contains
I have the following 3 classes Book Product SpecialOptions There are many Books, and
I have two Classes, one for ViewModel and one for Product . The Product

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.