Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Nico44's Profile

GitHub User: Nico44

Comments by

Avatar

For using this with associations I found the following worked for me (I am displaying a list of transactions, the association is a category). In my Transactions controller:

ruby
  def index
    if params[:sort] == "category"
      @transactions = sort_by_category
    else
      @transactions = sort
    end
  end
  
  private
  
    def sort
      current_user.transactions.order(sort_column + " " + sort_direction).page(params[:page])
    end
    
    def sort_by_category
      current_user.transactions.paginate(
            :page => params[:page],
            :include => :category,
            :order => "categories.name #{sort_direction}")
    end
  
    def sort_column
      Transaction.column_names.include?(params[:sort]) ? params[:sort] : "date"
    end
  
    def sort_direction
      %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
    end

I'm paging the results with will_paginate but if not paging something along the lines of the following would work I believe:

ruby
current_user.transactions.find(:all, :include => :category, :order => "categories.name #{sort_direction}")
Avatar

Thanks very much, that seems to have done it!

Avatar

Anyone else getting javascript errors with the Sass variation, i.e.

"$("a[rel=popover]").popover is not a function
[Break On This Error]

$("a[rel=popover]").popover();"

Looks like for some reason the bootstrap js files aren't getting served up.