Sign in through GitHub

RailsCasts Pro episodes are now free!

Learn more or hide this

rjstires's Profile

GitHub User: rjstires

Comments by

Avatar

For those trying, if have not already, to sort by association or be more specific with which columns can be sorted;

ruby
  def sort_column
    acceptable_cols = ["users.name", "users.email", "addresses.city", "addresses.state"]
    acceptable_cols.include?(params[:sort]) ? params[:sort] : "name"
  end

Just specifying an array of the allowed columns, rather than relying on the columns defined by the model allows you better control

I don't know if this is the best solution, I'm about two weeks new to Ruby and RoR.