Ordering .each results in the view...
Posted
by bgadoci
on Stack Overflow
See other posts from Stack Overflow
or by bgadoci
Published on 2010-05-19T15:20:18Z
Indexed on
2010/05/19
15:30 UTC
Read the original article
Hit count: 203
I am wondering if it is possible to dictate the order (i.e. :order => 'created_at DESC') within the view. I realize that logic in the view is not ideal but I seem to be having some problems locating where to affect this output.
For instance, here is my code:
<% @user.questions.each do |question| %>
<%= link_to_unless_current h (question.title), question %>
Created about <%= time_ago_in_words h(question.created_at) %> ago
Updated about <%= time_ago_in_words h(question.updated_at) %> ago
<%= link_to 'Edit', edit_question_path(question) %> |
<%= link_to 'Destroy', question, :confirm => 'Are you sure?', :method => :delete %>
<% end %>
In my QuestionsController I have the following index action but it is not affecting the output from the code above.
class QuestionsController < ApplicationController
def index
@questions = Question.all(:order => 'created_at DESC', :limit => 20)
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @questions }
end
end
end
© Stack Overflow or respective owner