0

Hello I want to make simple shopping cart. I am a beginner in programming. So please help. I have items with prices and quantities. I want to place button "Plus One", so when i press it should add one to quantity.

<td><%= item.name %></td>
<td><%= item.price %></td>
<td><%= item.quantity %></td>
<td><%= link_to 'Show', item %></td>
<td><%= link_to 'Edit', edit_item_path(item) %></td>
<td><%= link_to 'Destroy', item, :confirm => 'Are you sure?', :method => :delete %></td>
<td><%= link_to "Plusone" %></td>

3 Answers 3

2

Innocent suggestion. Buy a copy of Agile Web Development with Rails 4th Ed If I remember correctly this is the same example solved there through out the book. And it worth buying.

Sign up to request clarification or add additional context in comments.

Comments

1

To be frank, this is kind of a difficult problem for a beginner. If you want a button that does nothing but add one to the quantity, you're talking about defining a custom action, so you need to read up on Rails routes. Here's a good Railscast addressing this. There's also a follow-up episode.

Next, if you want this to dynamically update a field on the page without reloading, you're talking about an AJAX call to your custom action. Here's a Railscast for Rails 2, and here's a Railscast for Rails 3. These should have the information you need to make an AJAX call to your controller action and handle the response, either with a success handler or a js.erb template.

Comments

0

In addition to the sources mentioned above, other useful sources are: Ruby on rails guides, 'Head first rails' book:)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.