Skip to content

Instantly share code, notes, and snippets.

@dmoney
Created November 14, 2016 00:36
Show Gist options
  • Save dmoney/a992748c7b59bc4f661ad2b2f0ff487a to your computer and use it in GitHub Desktop.
Save dmoney/a992748c7b59bc4f661ad2b2f0ff487a to your computer and use it in GitHub Desktop.
refreshylist
<table>
<thead>
<tr>
<th>Item</th>
</tr>
</thead>
<tbody>
<% @list.each do |item| %>
<tr>
<td><%= item %></td>
</tr>
<% end %>
</tbody>
</table>
<table>
<thead>
<tr>
<th>Item</th>
</tr>
</thead>
<tbody>
<% @list.each do |item| %>
<tr>
<td><%= item %></td>
</tr>
<% end %>
</tbody>
</table>
class HomepagesController < ApplicationController
before_action :set_items, only: [:index, :div]
layout 'application', except: :div
# GET /homepages
# GET /homepages.json
def index
end
def div
end
private
def set_items
@list = (1..5).collect { |_| rand 0..10}
end
end
<p id="notice"><%= notice %></p>
<h1>Homepage</h1>
<div id="list_container">
<%= render 'homepages/div' %>
</div>
<br>
<button onclick="$('#list_container').load('/homepages/div');">Refresh</button>
Rails.application.routes.draw do
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
get '/homepages', to: 'homepages#index'
get '/homepages/div', to: 'homepages#div'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment