Skip to content

Instantly share code, notes, and snippets.

@Brandonmchu
Last active December 19, 2015 05:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Brandonmchu/5903759 to your computer and use it in GitHub Desktop.
Save Brandonmchu/5903759 to your computer and use it in GitHub Desktop.
#controller
def index
@bikes = Bike.order('created_at DESC').limit(50).all
@bikesnew = @bikes.find_all { |bike| bike.created_at > "2013-07-01 17:58:14" }
respond_to do |format|
format.js { render :bike_post_ajax }
format.html
end
end
#bike_post_ajax.js.erb
$('table').prepend("<%= j(render('bike_post', :bike=> @bikesnew)) %>")
#_bike_post.html.erb
<% bike.each do |single| %>
<tr>
<td>$<%= single.price %>0</td>
<% if single.posted != nil %>
<td><%= image_tag single.posted, :height => '200', :width => '200' %></td>
<% else %>
<td><%= image_tag 'y-u-no-guy.jpg' %></td>
<% end %>
<td><%= link_to single.title, single.url, :target => '_blank' %></td>
<td><%= single.location %></td>
<td><%= single.created_at.strftime("%b %d, %H:%M") %></td>
</tr>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment