Ilia Kazantsev
Ilia Kazantsev

Reputation: 13

Need help with rails' basics

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>

Upvotes: 0

Views: 87

Answers (3)

Radhika
Radhika

Reputation: 2561

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

Upvotes: 0

Samo
Samo

Reputation: 8240

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.

Upvotes: 1

Nishant
Nishant

Reputation: 55856

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.

Upvotes: 2

Related Questions