【发布时间】:2014-03-31 09:24:03
【问题描述】:
我在使用我添加到我的投资组合网站的新功能时遇到了一些问题。我有许多投资组合条目,现在我已经给出了类别。迁移一切正常,并且该部分运行良好。
我遇到的唯一问题是按各自类别中的降序排列组合项目。
Show.html.haml(针对个别类别)
-if @tag.portfolios.size > 0
-@tag.portfolios.each do |portfolio|
=link_to markdown(portfolio.content).first(72).html_safe, portfolio
%br
%p.text-right
-if User.find_by_id(session[:user_id])
=link_to 'Edit', edit_portfolio_path(portfolio)
|
=link_to 'Delete', portfolio, method: :delete, data: { confirm: 'Are you sure?' }
-else
%br
-else
%p Oops, I don't know what you're searching for - but it's not here!
类别控制器
def index
@tags = Tag.all
end
def show
@portfolios = Portfolio.all( :order => "created_at DESC" )
end
我知道这很明显,但我就是不知道是什么。
【问题讨论】:
-
您的意思是点击类别,您应该可以看到该类别下的所有投资组合都是DESC顺序。对吗?
-
点击类别后,您会看到相关的投资组合条目以降序排列。
标签: ruby ruby-on-rails-3 ruby-on-rails-4 haml