【发布时间】:2015-11-19 22:09:23
【问题描述】:
我是 [菜鸟] 玩弄 Phoenix 框架并构建一个小型 Twitter 克隆的乐趣。我一切正常,但是,我想按updated_at 字段(升序)对推文进行排序。正如您从 tweet_controller 中看到的那样,我尝试过使用 order_by 子句,但这对我没有任何作用。
问题
我如何实现这一目标?在 EEx 内还是在 tweet_controller 本身内?
tweet/index.html.eex
<div class="row">
<%= for tweet <- @tweets do %>
<h4><%= tweet.tweet %></h4>
<% end %>
</div>
controllers/tweet_controller.ex
...
alias TodoApp.Tweet
def index(conn, _params) do
tweets = Repo.all(Tweet, order_by: tweet)
render(conn, "index.html", tweets: tweets)
end
...
【问题讨论】:
标签: elixir phoenix-framework ecto