How to make a rails app arrange user posts(events) by date and delete
events that have passed?
I set up an event listing site and would like rails to automatically sort
these links(events) by date and delete them after the day has passed.
After extensive reading, I assume deleting posts that have passed is a
cron job. I look forward to any suggestions for that. Right here, I am
attempting to list these events by a datetime field in the form. Here's a
bit of code.
class LinksController < ApplicationController
def show
@link = Link.find(params[:id])
@comment = Comment.new
end
def new
authenticate_user!
@link = Link.new
end
def create
@link = Link.new(params[:link])
So in index.html.erb :
<% @links.each do |link| %>
<li><%= link_to link.title, link %><br></li>
<%= link_to "comments", link %>
And in the new link view I have:
<div class="field">
<%= f.label :datetime %><br />
<%= f.text_field :datetime %>
</div>
Could I just replace that
<% @links.each do |link| %>
with something like
<% @links.where("DATE(datetime) = DATE(?)", DateTime.now)
Even just a shove in the right direction would be much appreciated. Though
perhaps I need a @links.order_by ?
No comments:
Post a Comment