Reputation: 1650
So I have been following this article about how to use Ajax in Rails:
http://richonrails.com/articles/basic-ajax-in-ruby-on-rails
And so far as I understand, Rails does most of the code it self right? All that is done there it self is in thoes partials like this:
$("ul.errors").html("")
<% if @product.errors.any? %>
<% @product.errors.full_messages.each do |message| %>
$("ul.errors").append($("<li />").html("<%= message.html_safe %>"))
<% end %>
<% else %>
$(".product-index").html("<%= escape_javascript(render 'index') %>")
$("#product-modal").modal("hide")
<% end %>
And thoes just seem to take care of when the partial form should show up and when it should go away.
Is that right? That I don't need to learn much of Ajax it self, and this is just fine which is shown there.
Upvotes: 0
Views: 77
Reputation: 1548
for using jquery in rails and unobtrusive javascript I recommend watching these two casts from railscasts ,very helpful
http://railscasts.com/episodes/205-unobtrusive-javascript
http://railscasts.com/episodes/205-unobtrusive-javascript
Upvotes: 1
Reputation: 2470
That js files execute only after your call to certain actions of the controller.
You have a controller with actions like create/delete... So when you create a record, using create action, Rails executes create.js Same thing happens with other actions.
But in some situations, for e.g if you want a button to send some specific data with ajax you'll have to make something other than that in that tutorial.
But you're right, you don't have to know much ajax at the beginning.
Upvotes: 1