Skip to content

Commit

Permalink
Add collecting event autocomplete to collection object form; followin…
Browse files Browse the repository at this point in the history
…g bug prevents success most likely because project_id is nil (SELECT "collecting_events".* FROM "collecting_events" WHERE (verbatim_locality LIKE '%L%') AND "collecting_events"."project_id" IS NULL)
  • Loading branch information
mbeckman committed Aug 1, 2014
1 parent 86a972e commit 22cbc07
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 6 deletions.
12 changes: 12 additions & 0 deletions app/controllers/collecting_events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,19 @@ def list
end

def autocomplete
@collecting_events = CollectingEvent.find_for_autocomplete(params.merge(project_id: sessions_current_project_id)) # in model

data = @collecting_events.collect do |t|
{id: t.id,
label: CollectingEventsHelper.collecting_event_tag(t), # in helper
response_values: {
params[:method] => t.id
},
label_html: CollectingEventsHelper.collecting_event_tag(t) # render_to_string(:partial => 'shared/autocomplete/taxon_name.html', :object => t)
}
end

render :json => data
end

private
Expand Down
5 changes: 5 additions & 0 deletions app/models/collecting_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ def self.test
'var data = ' + result.to_json + ';'
end

def self.find_for_autocomplete(params)
where('verbatim_locality LIKE ?', "%#{params[:term]}%").with_project_id(params[:id])
# changed from 'cached' to 'verbatim_locality':
end

protected

# TODO: Draper Candidate
Expand Down
4 changes: 2 additions & 2 deletions app/views/collecting_events/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
</p>

<p>
<strong>Cached display:</strong>
<%= @collecting_event.cached_display %>
<strong>Cached:</strong>
<%= @collecting_event.cached %>
</p>

<p>
Expand Down
8 changes: 7 additions & 1 deletion app/views/collection_objects/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,13 @@

<div class="field">
<%= f.label :collecting_event %><br>
<%= f.select :collecting_event_id, options_from_collection_for_select(CollectingEvent.with_project_id($project_id).all, :id, :cached_display) -%>
<%#= f.select :collecting_event_id, options_from_collection_for_select(CollectingEvent.with_project_id($project_id).all, :id, :cached_display) -%>
<%= render :partial => 'elements/forms/ajax_select', :locals => {:controller => 'collecting_events', # controller location of autocomplete we want to run
:object => 'collection_object', # symbolic reference to the form instance
:method => 'collecting_event_id', # foreign key id
:tag_id => 'collecting_event_id_for_collection_object', # html id
:display => object_tag(@collection_object.collecting_event)} %>

</div>

<div class="field">
Expand Down
6 changes: 3 additions & 3 deletions app/views/otus/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<%= f.label :taxon_name %><br>
<%= render :partial => "elements/forms/ajax_select", :locals => {:controller => 'taxon_names',
:object => 'taxon_name',
:method => 'taxon_name_id_id',
:tag_id => "taxon_name_id_for_new_otu",
:display => object_tag(@taxon_name) } %>
:method => 'taxon_name_id',
:tag_id => "taxon_name_id_for_otu",
:display => object_tag(@otu.taxon_name) } %>
</div>

<div class="actions">
Expand Down

0 comments on commit 22cbc07

Please sign in to comment.