我试图允许用户点击一个月,并列出该月的员额(如进行搜查,但没有搜索表)。 我希望他们能够仅仅点击这个月的名字。
我可以建立一个与某些月相关的员额档案,并在旁边厅显示这些员额,但我希望该月的员额取代员额指数行动中所列的员额。
这里是我目前使用的档案。
In the Posts Controller...
缩略语
@posts = Post.find(:all, :order => "created_at DESC")
@recent_posts = Post.all(:order => "created_at DESC")
@posts_by_month = Post.find(:all, :order => "created_at DESC").group_by { |post| post.created_at.strftime("%B %Y")}
respond_to do |format|
format.html # index.html.erb
format.xml { r结束er :xml => @posts }
结束
结束
Here is what is in the corresponding index view...
blog.archive<% @posts_by_month.each do |monthname, posts| %>
<p class="month-archive"><%= monthname %></p>
<div class="archive">
<ul class="archive">
<% posts.each do |post| %>
<li class="archive"><p class="archive-post"><%= post.title %></p></li>
<% 结束 %>
</ul>
</div>
This will list the posts based on the month they were created in, but this only gets me halfway there. I want the user to be able to click on the month and have it show the entire posts, and not just a listing in the sidebar.
希望具有某种意义。
感谢任何帮助。 我试图找到一个例子,看一看,以便我能够总结一下如何做到这一点,并且未能做到。
感谢!
A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.R.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.A.