English 中文(简体)
创建铁路局
原标题:Creating Blog Post Archive In Rails

我试图允许用户点击一个月,并列出该月的员额(如进行搜查,但没有搜索表)。 我希望他们能够仅仅点击这个月的名字。

我可以建立一个与某些月相关的员额档案,并在旁边厅显示这些员额,但我希望该月的员额取代员额指数行动中所列的员额。

这里是我目前使用的档案。

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.

问题回答

我认为,你需要制定新的方法,在邮局控制员中用一个月的时间,并创造像这样的路线。

match  posts/month/:month  =>  Posts#month , :as=> posts_by_month

在邮局控制员的新方法中,您将使用以下论点:params[:个月],以选择适当的条款,编号<>:个月=>params[:个月]。

<><>>>

在网页上,你将每月创建链接到<代码>张贴/月:月。 www.un.org/chinese/ga/president

另外,似乎你正在两次收集同样的数据。 看来,@posts和@recent_posts正在从事同样的工作。 你们也许要消除其中一人,以改善业绩。





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签