SHARE
TWEET

Untitled

a guest Jun 19th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - layout
  2. <div id="base">
  3.    <%= link_to "Ajax!", remote: true, class: "getUsers" %>
  4.     <div class="wrapper"></div>
  5. </div>
  6.  
  7. - controller
  8. class UsersController < ApplicationController
  9.   layout false
  10.  
  11.   def index
  12.     @users = User.all
  13.   end
  14. end
  15.  
  16. - view
  17. <div id="userCtrl">
  18.   <ul>
  19.     <% @users.each do |u| %>
  20.         <li><%= u.name %></li>
  21.      <% end %>
  22.   </ul>
  23. </div>
  24.  
  25. - css
  26. #userCtrl {
  27.   # CSS for userCtrl
  28. }
  29.  
  30. - js
  31. $(function() {
  32.   $(document).on("ajax:success", '#userCtrl .getUsers', function(q, data, xhr){
  33.     $("#base .wrapper").html(data);
  34.   });
  35. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top