You can do something like this :
if ..something..
@posts = Post.where(..something..)
else
@posts = Post.where(..something..)
end
@posts = @posts.all(:order => ..something..)
It’s better to do this, in Rails 3 :
@posts = @posts.order(..something..)
More Related Contents:
- Using helpers in model: how do I include helper dependencies?
- Is there a way to get a collection of all the Models in your Rails app?
- Rails :dependent => :destroy VS :dependent => :delete_all
- ActiveRecord.find(array_of_ids), preserving order
- Rails model without database
- How do I replace accented Latin characters in Ruby?
- Using Rails serialize to save hash to database
- Rails 3: Get Random Record
- How to handle Ruby on Rails error: “Please install the postgresql adapter: `gem install activerecord-postgresql-adapter'”
- Altering the primary key in Rails to be a string
- Rails find_or_create_by more than one attribute?
- LEFT OUTER joins in Rails 3
- Rails: ActiveRecord query based on association value
- How to test for (ActiveRecord) object equality
- Rails 3, has_one / has_many with lambda condition
- How do i work with two different databases in rails with active records?
- Rails ActiveRecord: Find All Users Except Current User
- query , can not select column count
- How to use ActiveRecord in a ruby script outside Rails?
- Ruby on Rails – Access controller variable from model
- Regular expressions with validations in RoR 4
- What are the brackets [5.1] after ActiveRecord Migration and how does it work? [duplicate]
- delete_all vs destroy_all?
- Converting an array of objects to ActiveRecord::Relation
- How to implement Active Record inheritance in Ruby on Rails?
- Rails: Skinny Controller vs. Fat Model, or should I make my Controller Anorexic?
- Store the day of the week and time?
- Is there a way to avoid automatically updating Rails timestamp fields?
- Rails gem rails3-jquery-autocomplete: How do I query multiple fields
- Rails Object Relationships and JSON Rendering