Skip to content

Commit

Permalink
Refactoring the otu ajax example.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjy committed Aug 1, 2014
1 parent 2669ba9 commit 46eac3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/otus_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def search
redirect_to otu_path(params[:otu][:id])
end

def auto_complete
@otus = Otu.where('name LIKE ?', "#{params[:term]}%") # find_for_auto_complete(conditions, table_name)
def autocomplete
@otus = Otu.find_for_autocomplete(params)

data = @otus.collect do |t|
{id: t.id,
Expand Down
5 changes: 5 additions & 0 deletions app/models/otu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ def sv_duplicate_otu
end
#endregion

def self.find_for_autocomplete(params)
where('name LIKE ?', "#{params[:term]}%")
end


# Generate a CSV version of the raw Otus table for the given project_id
# Ripped from http://railscasts.com/episodes/362-exporting-csv-and-excel
def self.generate_download(project_id: nil)
Expand Down
18 changes: 8 additions & 10 deletions app/views/elements/forms/_ajax_select.html.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<%# Configuration for all pickers -%>
<% css_class ||= 'ajaxPicker' -%>
<% action ||= "auto_complete".html_safe -%>
<% action ||= "autocomplete".html_safe -%>
<%# Taxon name specific -%>
<% name_group ||= 'all' -%>
<% use_proj ||= 'true' -%>
<%# Geog name specific -%>
<% geog_types ||= 'all' -%>
<% url = url_for({:proj_id => (@proj ? @proj.id : nil), :controller => controller, :action => action, :tag_id => tag_id, :method => "#{object}[#{method}]",
:name_group => name_group, :use_proj => use_proj, :escape => false, :geog_types => geog_types}) -%>
<% url = url_for({
proj_id: (@proj ? @proj.id : nil),
controller: controller,
action: action,
tag_id: tag_id,
method: "#{object}[#{method}]",
escape: false}) -%>

<input autocomplete="off"
title="find and select <%= controller.pluralize.html_safe -%>"
Expand Down

0 comments on commit 46eac3a

Please sign in to comment.