RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
<!DOCTYPE html> <html> <head> <title>UJS Example</title> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript" charset="utf-8"> $(function() { $("#alert").click(function() { alert(this.getAttribute("data-message")); return false; }) }) </script> </head> <body> <h1><a href="#" id="alert" data-message="Hello UJS!">Click Here</a></h1> </body> </html>
<%= javascript_include_tag :defaults %> <!-- or --> <%= javascript_include_tag "http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", "jquery.rails.js" %> <%= csrf_meta_tag %>
<% form_tag products_path, :method => :get, :remote => true do %> <p> <%= text_field_tag :search, params[:search] %> <%= submit_tag "Search", :name => nil %> </p> <% end %> <div id="products"> <%= render @products %> </div>
$("products").update("<%= escape_javascript(render(@products)) %>"); // or $("#products").html("<%= escape_javascript(render(@products)) %>");