Skip to content

Instantly share code, notes, and snippets.

@cknoxrun
Created December 8, 2015 16:20
Show Gist options
  • Select an option

  • Save cknoxrun/abc5b2af5a536701b4b9 to your computer and use it in GitHub Desktop.

Select an option

Save cknoxrun/abc5b2af5a536701b4b9 to your computer and use it in GitHub Desktop.
# Note that this action responds to fracked up datatable parameters.
# If you need to use this for some other reason (HTML, etc), you
# might want to consider moving it into it's own method
# (datatable or something).
def index
# These are the columns, in the correct order, used by datatables
cols = [:gene_name, :gene_symbol, :gene_id, :interaction, :chromosome]
@gene_regulations =
if params[:kind] == 'up_regulated'
@compound.gene_regulations.up_regulated
else
@compound.gene_regulations.down_regulated
end.includes(:articles)
# This needs to be here so we can only count the regulations by kind,
# but we don't have any searches applied yet
@total_count = @gene_regulations.count
if params[:search][:value].present?
query_cols = cols.map { |c| "`#{c}` LIKE :q" }
@gene_regulations = \
@gene_regulations.where(query_cols.join(" OR "),
q: "%#{params[:search][:value]}%")
end
# This has to be here, it needs to be the count before any
# pagination has been done and it needs to take into account
# search terms.
@filter_count = @gene_regulations.count
if params[:order].present?
params[:order].each do |number, order_col|
column = cols[order_col[:column].to_i]
@gene_regulations = \
@gene_regulations.order("`#{column}` #{order_col[:dir]}")
end
end
if params[:start].present?
@gene_regulations = @gene_regulations.offset(params[:start].to_i)
end
if params[:length].present?
@gene_regulations = @gene_regulations.limit(params[:length].to_i)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment