Last active
December 19, 2015 02:49
-
-
Save akofink/5885562 to your computer and use it in GitHub Desktop.
Rails controller ActiveRecord calls.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def index | |
return redirect_to action: "index" if params[:reset] | |
params[:filter] ||= {} | |
params[:page] ||= "1" | |
params[:per_page] ||= "100" | |
params[:filter][:type] ||= "Phylum" | |
params[:order] ||= 'organism.official_name ASC' | |
params[:order] = 'organism.id' if params[:order] == 'id' | |
if params[:order].include?("phylum_id") | |
params[:order] << ", official_name #{params[:order].include?("ASC") ? "ASC" : "DESC"}" | |
end | |
criteria = SequenceCriteria.determine_sequence_criteria params | |
@results = Sequence.select("distinct organisms.*").order(params[:order]).includes(:titles).joins(criteria[:joins]). | |
where(criteria[:cond_str], criteria[:cond_crit]) | |
@results = @results.page(params[:page].to_i).per_page(params[:per_page].to_i) if params[:per_page] != 'All' | |
respond_to do |format| | |
format.html | |
format.js | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment