Ticket #206: tagsearch.patch

File tagsearch.patch, 1.9 KB (added by chippy, 12 years ago)

tag search form and searching for tags using like

  • app/controllers/trace_controller.rb

     
    4747   
    4848    if params[:tag]
    4949      @tag = params[:tag]
    50       conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)"
    51       conditions << @tag
     50      conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag LIKE ?)"
     51      conditions << @tag + '%'
    5252    end
    5353   
    5454    conditions[0] += " AND gpx_files.visible = 1"
     
    204204    end
    205205
    206206    if params[:tag]
    207       conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag = ?)"
    208       conditions << params[:tag]
     207      conditions[0] += " AND EXISTS (SELECT * FROM gpx_file_tags AS gft WHERE gft.gpx_id = gpx_files.id AND gft.tag LIKE ?)"
     208      conditions << params[:tag] + '%'
    209209    end
    210210
    211211    traces = Trace.find(:all, :include => :user, :conditions => conditions,
  • app/views/trace/_trace_search.rhtml

     
     1<%  form_tag '', :method => :get  do -%>
     2<%= text_field_tag :tag, nil, :size => 15 -%>
     3<%= submit_tag "Search for tag" -%>
     4<% end %>
  • app/views/trace/_trace_header.rhtml

     
    11<h1><%= h(@title) %></h1>
    2 
     2<p>
     3<%= render :partial => 'trace_search' %>
     4</p>
    35<%= auto_discovery_link_tag :atom, :action => 'georss', :display_name => @display_name, :tag => @tag %>
    46
    57<p>