Greetings,
I'm new to Ruby on Rails. I'm working through "Agile Web Development
with Rails 3rd Edition" and it is going quite well. However, there
are times I don't quite understand *why* I'm doing something. For
some items, I think I understand, but I would like some confirmation.
So, I'm going to post my questions here and I hope that someone can
help me in understanding.
In Chapter 9, I'm working on creating an AJAX-based shopping cart.
So, I'm replacing this:
<!-- START:add_to_cart -->
<%= button_to "Add to Cart", :action => 'add_to_cart', :id => product
%>
<!-- END:add_to_cart -->
With this:
<!-- START:form_remote_tag -->
<% form_remote_tag :url => { :action => 'add_to_cart', :id =>
product } do %>
<%= submit_tag "Add to Cart" %>
<% end %>
Questions on this:
I can explain that the first second is doing this: "Use ruby helper
button_to to add a button for each item, and it calls the action
add_to_cart, passing back the product that was selected"
I can't seem to be able to explain the second section. "The rails
helper form_remote_tag is called, which is similar to a method call
and the :url is similar to passing a parameter to a method. The
items between { and } are the values for the :url parameter."
Correct?
What is the "submit_tag"? Is that similar to the input type="submit"
in HTML? Is it basically saying, show a button?
Why is the do%> and <% end %> part needed? Is this saying do the
following ruby code?
The difference between the two seconds, as the book explains, is that
the second sends an AJAX request instead of a POST request. I read
that, I think I understand it, but I don't exactly know why there is a
difference. Can someone explain?
I'll just start with this. Thanks,
Andrew
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---