Skip to content

Commit

Permalink
Merge pull request openfarmcc#313 from rickcarlino/search-with-get
Browse files Browse the repository at this point in the history
Search with get (for Ganalytics, shareable URLS)
  • Loading branch information
RickCarlino committed Nov 11, 2014
2 parents bd55f2f + c6e94b1 commit ab7a6ba
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
9 changes: 7 additions & 2 deletions app/controllers/crop_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ class CropSearchesController < ApplicationController
skip_before_filter :verify_authenticity_token, only: :search

def search
query = (params[:cropsearch] && params[:cropsearch][:q]).to_s
@crops = Crop.search(query, fields: ['name^20', 'common_names^10', 'binomial_name^10', 'description'], limit: 25)
query = params[:q].to_s
@crops = Crop.search(query,
limit: 25,
fields: ['name^20',
'common_names^10',
'binomial_name^10',
'description'])
if @crops.empty?
@crops = Crop.search('*', limit: 25)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class HomeController < ApplicationController
class HomesController < ApplicationController
def show
@featured_crops = Crop.desc(:guides_count).limit(9)
end
Expand Down
File renamed without changes.
11 changes: 5 additions & 6 deletions app/views/home/show.html.erb → app/views/homes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,23 @@
<%= t 'home.step_3' %>
</li>
</ul>
<%= form_for :cropsearch, url: crop_search_via_post_path, method: 'post' do |f| %>
<form action="<%= crop_search_via_get_path %>" method="get" >
<!-- ^NOT A MISTAKE!! Avoiding rails helpers for cleaner URLs and Ganalytics. -->
<div class="row">
<div class="small-12 small-centered columns">
<div class="search-bar-container">
<div class="search-bar" ng-app="searchApp" ng-controller="searchCtrl">
<div class="search-input-container">
<%= text_field_tag :q, nil, {class: 'search-input', name: 'cropsearch[q]', placeholder: t('home.placeholder'),
maxlength: '120', autocomplete: 'off', 'ng-model'=>'query', 'ng-change'=> 'search()',
'typeahead'=>'crop.name for crop in crops', 'typeahead-wait-ms'=>'555', ' typeahead-min-length'=>'3'} %>
<input typeahead-min-length="3" autocomplete="off" class="search-input ng-pristine ng-valid ng-valid-maxlength ng-touched" id="q" maxlength="120" name="q" ng-change="search()" ng-model="query" placeholder="<%= t('home.placeholder') %>" type="text" typeahead-wait-ms="555" typeahead="crop.name for crop in crops">
</div>
<div class="search-button-container">
<%= f.submit t('home.search'), data: { disable_with: "Searching..." }, class: 'search-button button postfix' %>
<input class="search-button button postfix" data-disable-with="Searching..." type="submit" value="<%= t('home.search') %>">
</div>
</div>
</div>
</div>
</div>
<% end %>
</form>
</div>
<a href="#explore-community-favorites" id="explore-community-favorites" class="explore-community-favorites text-center">
<h2><%= t('home.explore_community_favorites') %></h2>
Expand Down
14 changes: 6 additions & 8 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
<!--<![endif]-->
<head>
<meta charset="utf-8" />

<%= render 'meta/global' %>
<%= render 'meta/touch' %>
<%= render 'meta/page' %>
<%= render 'meta/social_network' %>

<!-- Uncomment to make IE8 render like IE7 -->
<!-- <meta http-equiv="X-UA-Compatible" content="IE=7" /> -->

Expand Down Expand Up @@ -57,22 +57,20 @@
<!-- Search box Section -->
<%# Added the reference to "/" because root_path was being redefined to have /en|nl/ whichever way I put it. %>
<% unless current_page?(root_path) or current_page?("/") %>
<%= form_for :cropsearch, url:
crop_search_via_post_path, method: 'post' do |f| %>
<form action="<%= crop_search_via_get_path %>" method="get" >
<div class="left">

<div class="row collapse postfix-round">

<div class="small-4 columns">
<%= f.text_field :q, id: :q, maxlength:"120", class: 'search', placeholder: t('home.placeholder') %>

<input class="search" id="q" maxlength="120" name="q" placeholder="<%= t('home.placeholder') %>" size="120" type="text">
</div>
<div class="small-2 columns end">
<%= f.submit t('home.search'), data: { disable_with: "Searching..." }, class: 'small button postfix' %>
<input class="small button postfix" data-disable-with="Searching..." type="submit" value="<%= t('home.search') %>">
</div>
</div>
</div>
<% end %>
</form>
<% end %>

<!-- Right Nav Section -->
Expand Down
18 changes: 9 additions & 9 deletions app/views/meta/_touch.html.erb
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<!-- For Chrome for Android: -->
<link rel="icon" sizes="192x192" href="touch-icon-192x192.png">
<link rel="icon" sizes="192x192" href=" <%= image_path("touch-icon-192x192.png") %>>
<!-- For iPhone 6 Plus with @3× display: -->
<link rel="apple-touch-icon-precomposed" sizes="180x180" href="icons/apple-touch-icon-180x180-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="180x180" href=" <%= image_path("apple-touch-icon-180x180-precomposed.png") %>>
<!-- For iPad with @2× display running iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="icons/apple-touch-icon-152x152-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href=" <%= image_path("apple-touch-icon-152x152-precomposed.png") %>>
<!-- For iPad with @2× display running iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="144x144" href="icons/apple-touch-icon-144x144-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="144x144" href=" <%= image_path("apple-touch-icon-144x144-precomposed.png") %>>
<!-- For iPhone with @2× display running iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="120x120" href="icons/apple-touch-icon-120x120-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="120x120" href=" <%= image_path("apple-touch-icon-120x120-precomposed.png") %>>
<!-- For iPhone with @2× display running iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="icons/apple-touch-icon-114x114-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href=" <%= image_path("apple-touch-icon-114x114-precomposed.png") %>>
<!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS ≥ 7: -->
<link rel="apple-touch-icon-precomposed" sizes="76x76" href="icons/apple-touch-icon-76x76-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="76x76" href=" <%= image_path("apple-touch-icon-76x76-precomposed.png") %>>
<!-- For the iPad mini and the first- and second-generation iPad (@1× display) on iOS ≤ 6: -->
<link rel="apple-touch-icon-precomposed" sizes="72x72" href="icons/apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon-precomposed" sizes="72x72" href=" <%= image_path("apple-touch-icon-72x72-precomposed.png") %>>
<!-- For non-Retina iPhone, iPod Touch, and Android 2.1+ devices: -->
<link rel="apple-touch-icon-precomposed" href="icons/apple-touch-icon-precomposed.png"><!-- 57×57px -->
<link rel="apple-touch-icon-precomposed" href="<%= image_path("apple-touch-icon-precomposed.png") %> ><!-- 57×57px -->
6 changes: 2 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
get 'users/finish' => 'users#finish'
put 'users' => 'users#update'
end
# Accept searches via POST and GET so that users can search with forms -or-
# shareable link.

scope '(:locale)', locale: /en|nl/ do
root to:'home#show'
root to: 'homes#show'
post '(:locale)/crop_search' => 'crop_searches#search',
as: :crop_search_via_post
get '(:locale)/crop_search' => 'crop_searches#search',
Expand Down Expand Up @@ -50,5 +48,5 @@
delete 'token', to: 'tokens#destroy'
end

get '/:locale' => 'home#show'
get '/:locale' => 'homes#show'
end

0 comments on commit ab7a6ba

Please sign in to comment.