Im trying to make a side bar for my blog archive that lists out all the months for my blog entries, so when you click on a link such as “June 2007” all the blogs from June 07 are loaded.
Heres my link_to
<%= link_to month.first.strftime("%B %Y"), blog_archive_month_path(month.first.strftime("%Y-%m-%d")) %>
month.first is a record I pulled up. Should my controller look something like this?:
@blog_posts = BlogPost.where(:created_at.strftime("%Y-%m-%d") => params[:date]).(:select => "title, id, slug, created_at", :order => "created_at DESC")
I was hoping I could convert the records’ created_by field to a format I could pass in an match but I get an undefined method erro
Basically I agree with what Dan Croak is saying (+1). The only mistake in his answer is that
.to_datethrows an error if there is not a complete date string inparams[:date](like in his example). So my suggestion would be:View:
Controller:
The problem with your original code is that you are trying to call
strftimeon:created_at, which is not possible.Or if you don’t like a full date in your URL, you could do this:
And: