Skip to content

Instantly share code, notes, and snippets.

@ysaito8015
Last active August 29, 2015 14:16
Show Gist options
  • Save ysaito8015/011f629ae0d4bcaf1a50 to your computer and use it in GitHub Desktop.
Save ysaito8015/011f629ae0d4bcaf1a50 to your computer and use it in GitHub Desktop.
Heroku で ransack による日付一致検索 ref: http://qiita.com/ysaito8015@github/items/66b1985f695da4efc528
app[web.1]: Parameters: {"utf8"=>"✓", "q"=>{"order_date_cont"=>"2015-03-02"}}
app[web.1]: Purchase Load (4.9ms) SELECT DISTINCT "purchases".* FROM "purchases" WHERE ("purchases"."order_date" ILIKE '%2015-03-02%') ORDER BY "purchases"."order_date" DESC
app[web.1]: PG::UndefinedFunction: ERROR: operator does not exist: date ~~* unknown
app[web.1]: LINE 1: ... FROM "purchases" WHERE ("purchases"."order_date" ILIKE '%20...
app[web.1]: ^
app[web.1]: HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
app[web.1]: SELECT DISTINCT "purchases".* FROM "purchases" WHERE ("purchases"."order_date" ILIKE '%2015-03-02%') ORDER BY "purchases"."order_date" DESC
app[web.1]: Rendered shared/_search_result_box.html.erb(6.9ms)
app[web.1]: Completed 500 Internal Server Error in 69ms
private
ransacker :order_date do
Arel.sql('date(order_date)')
end
class PurchaseController < ApplicationController
private
def search_params
search_conditions = %i(
order_date_date_equals
)
params.require(:q).permit(search_conditions)
end
end
Ransack.configure do |config|
config.add_predicate 'date_equals',
arel_predicate: 'eq',
formatter: proc { |v| v.to_date },
formatter: proc { |v| v.present? },
type: :string
end
<label>注文日</label>
<%= f.search_field :order_date_date_equals, class: 'date' %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment