SlideShare a Scribd company logo
1 of 20
Download to read offline
Search Form for Rails
Roppongi.rb #11 2019/06/20(木)
1
自己紹介
名前: 神速
GitHub: @sinsoku (アイコン右上)
Twitter: @sinsoku_listy (アイコン右下)
Rails歴: それなり
2
Searching
1. Elasticsearch
2. Amazon CloudSearch
3. Ransack
4. self implementation
5. other...?
3
4
controller
def index
@q = Person.ransack(params[:q])
@people = @q.result(distinct: true)
end
5
view
<%= search_form_for @q do |f| %>
# Search if the name field contains...
<%= f.label :name_cont %>
<%= f.search_field :name_cont %>
# Search if an associated articles.title starts with...
<%= f.label :articles_title_start %>
<%= f.search_field :articles_title_start %>
# Attributes may be chained. Search multiple attributes for one value...
<%= f.label :name_or_description_or_email_or_articles_title_cont %>
<%= f.search_field :name_or_description_or_email_or_articles_title_cont %>
<%= f.submit %>
<% end %>
6
Pros
• easy to introduce
• realizes complex conditions with Advanced Mode
• searches by associations
• used by many people(, and easy to find references)
7
Cons
• includes many hack codes for ActiveRecord
• difficult to maintenance
• CI failed on 5-2-stable
!
• I do not like the design about Authorization
8
Example
Support for Rails 6
https://github.com/activerecord-hackery/ransack/pull/1027
9
I came up with a new implementation
So, I am developing a gem to replace Ransack.
10
sinsoku/pickel
Pickel provides methods that make it
easy to build a search form for your
Rails app.
11
in controller
def index
search_params = Pickel.permit(params, :name, :age_gt, :posts_title_start)
@search = Pickel.search(User, search_params)
@users = @search.result
end
12
in view
<%= form_for @search do |f| %>
<%# Search records contains the value %>
<%= f.label :name_cont %>
<%= f.search_field :name_cont %>
<%# Search records grater than the value %>
<%= f.label :age_gt %>
<%= f.number_field :age_gt %>
<%# Search records an associated posts.title starts with the value %>
<%= f.label :posts_title_start %>
<%= f.search_field :posts_title_start %>
<%= f.submit %>
<% end %>
13
Concept (Difference from Ransack)
• refrains hack for ActiveRecord
• basically builds a SQL in ActiveRecord.merge
• (However, Arel is used)
• allows search conditions by the StrongParameter
• uses form_for as it is
14
Design 1
• handle search conditions with Hash
conditinos = {
name_eq: 'foo',
posts_title_start: 'bar'
}
15
Design 2
• Convert a condition to Relation
rel_1 = User.where(name: 'foo')
cond = Post.arel_table[:title].start('bar%')
rel_2 = User.joins(:posts).merge(Post.where(cond))
16
Design 3
• Merge all conditions
rel = rel_1.merge(rel_2)
17
Is this usable in production?
18
Sorry, it is still in development.
Once it has been implemented to replace
Ransack, I will be tagged v1.0.0.
19
Click Watch
!
or Star
20

More Related Content

Similar to Search Form for Rails

Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecordMark Menard
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails Hung Wu Lo
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldMarakana Inc.
 
Documenting from the Trenches
Documenting from the TrenchesDocumenting from the Trenches
Documenting from the TrenchesXavier Noria
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à RubyMicrosoft
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overviewYehuda Katz
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSarah Kiniry
 
Presentation.Key
Presentation.KeyPresentation.Key
Presentation.Keyguesta2b31d
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2Rory Gianni
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talkdtdannen
 
Django class based views
Django class based viewsDjango class based views
Django class based viewsjustinvoss
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2RORLAB
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxsalemsg
 

Similar to Search Form for Rails (20)

Rails3 changesets
Rails3 changesetsRails3 changesets
Rails3 changesets
 
Intro to Rails ActiveRecord
Intro to Rails ActiveRecordIntro to Rails ActiveRecord
Intro to Rails ActiveRecord
 
Elastic tire demo
Elastic tire demoElastic tire demo
Elastic tire demo
 
68837.ppt
68837.ppt68837.ppt
68837.ppt
 
mashraqi_farhan
mashraqi_farhanmashraqi_farhan
mashraqi_farhan
 
Template rendering in rails
Template rendering in rails Template rendering in rails
Template rendering in rails
 
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram ArnoldEfficient Rails Test Driven Development (class 3) by Wolfram Arnold
Efficient Rails Test Driven Development (class 3) by Wolfram Arnold
 
Documenting from the Trenches
Documenting from the TrenchesDocumenting from the Trenches
Documenting from the Trenches
 
Introduction à Ruby
Introduction à RubyIntroduction à Ruby
Introduction à Ruby
 
Struts 2
Struts 2Struts 2
Struts 2
 
Rails 3 overview
Rails 3 overviewRails 3 overview
Rails 3 overview
 
STC 2016 Programming Language Storytime
STC 2016 Programming Language StorytimeSTC 2016 Programming Language Storytime
STC 2016 Programming Language Storytime
 
Presentation.Key
Presentation.KeyPresentation.Key
Presentation.Key
 
RoR 101: Session 2
RoR 101: Session 2RoR 101: Session 2
RoR 101: Session 2
 
Django tech-talk
Django tech-talkDjango tech-talk
Django tech-talk
 
Django class based views
Django class based viewsDjango class based views
Django class based views
 
JS-05-Handlebars.ppt
JS-05-Handlebars.pptJS-05-Handlebars.ppt
JS-05-Handlebars.ppt
 
Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2Getting started with Rails (2), Season 2
Getting started with Rails (2), Season 2
 
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptxWRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
WRStmlDSQUmUrZpQ0tFJ4Q_a36bc57fe1a24dd8bc5ba549736e406f_C2-Week2.pptx
 
Django design-patterns
Django design-patternsDjango design-patterns
Django design-patterns
 

More from sinsoku listy

Rails6にいつ上げるか?
Rails6にいつ上げるか?Rails6にいつ上げるか?
Rails6にいつ上げるか?sinsoku listy
 
Rails Testing on Fargate
Rails Testing on FargateRails Testing on Fargate
Rails Testing on Fargatesinsoku listy
 
自己修復的なインフラ -Self-Healing Infrastructure-
自己修復的なインフラ -Self-Healing Infrastructure-自己修復的なインフラ -Self-Healing Infrastructure-
自己修復的なインフラ -Self-Healing Infrastructure-sinsoku listy
 
毎日gemをアップグレードする生活
毎日gemをアップグレードする生活毎日gemをアップグレードする生活
毎日gemをアップグレードする生活sinsoku listy
 
Rails 5.2: credentials
Rails 5.2: credentialsRails 5.2: credentials
Rails 5.2: credentialssinsoku listy
 
Randomly Failing Specs
Randomly Failing SpecsRandomly Failing Specs
Randomly Failing Specssinsoku listy
 
技術的負債とリファクタリング
技術的負債とリファクタリング技術的負債とリファクタリング
技術的負債とリファクタリングsinsoku listy
 
Git 初心者講座 by forkwell
Git 初心者講座 by forkwellGit 初心者講座 by forkwell
Git 初心者講座 by forkwellsinsoku listy
 
ES2015のカバレッジ計測
ES2015のカバレッジ計測ES2015のカバレッジ計測
ES2015のカバレッジ計測sinsoku listy
 
CSSのカバレッジツール
CSSのカバレッジツールCSSのカバレッジツール
CSSのカバレッジツールsinsoku listy
 
本当にあった怖い話 7つの幽霊 7つの成仏
本当にあった怖い話 7つの幽霊 7つの成仏本当にあった怖い話 7つの幽霊 7つの成仏
本当にあった怖い話 7つの幽霊 7つの成仏sinsoku listy
 
Awsでwindowsゲームを動かす
Awsでwindowsゲームを動かすAwsでwindowsゲームを動かす
Awsでwindowsゲームを動かすsinsoku listy
 
Action pack variantsの話
Action pack variantsの話Action pack variantsの話
Action pack variantsの話sinsoku listy
 
LT_Gitのfast fowardと継続的デリバリー
LT_Gitのfast fowardと継続的デリバリーLT_Gitのfast fowardと継続的デリバリー
LT_Gitのfast fowardと継続的デリバリーsinsoku listy
 
バージョン管理とGit
バージョン管理とGitバージョン管理とGit
バージョン管理とGitsinsoku listy
 
Git天空闘技場_ハンズオン
Git天空闘技場_ハンズオンGit天空闘技場_ハンズオン
Git天空闘技場_ハンズオンsinsoku listy
 
20101001 5分でわかるtrac pluginの作り方_slideshare
20101001 5分でわかるtrac pluginの作り方_slideshare20101001 5分でわかるtrac pluginの作り方_slideshare
20101001 5分でわかるtrac pluginの作り方_slidesharesinsoku listy
 

More from sinsoku listy (20)

Rails6にいつ上げるか?
Rails6にいつ上げるか?Rails6にいつ上げるか?
Rails6にいつ上げるか?
 
Rails Testing on Fargate
Rails Testing on FargateRails Testing on Fargate
Rails Testing on Fargate
 
ENGINEER WORK!!
ENGINEER WORK!!ENGINEER WORK!!
ENGINEER WORK!!
 
自己修復的なインフラ -Self-Healing Infrastructure-
自己修復的なインフラ -Self-Healing Infrastructure-自己修復的なインフラ -Self-Healing Infrastructure-
自己修復的なインフラ -Self-Healing Infrastructure-
 
毎日gemをアップグレードする生活
毎日gemをアップグレードする生活毎日gemをアップグレードする生活
毎日gemをアップグレードする生活
 
Rails 5.2: credentials
Rails 5.2: credentialsRails 5.2: credentials
Rails 5.2: credentials
 
Randomly Failing Specs
Randomly Failing SpecsRandomly Failing Specs
Randomly Failing Specs
 
技術的負債とリファクタリング
技術的負債とリファクタリング技術的負債とリファクタリング
技術的負債とリファクタリング
 
Git 初心者講座 by forkwell
Git 初心者講座 by forkwellGit 初心者講座 by forkwell
Git 初心者講座 by forkwell
 
Swift on Docker
Swift on DockerSwift on Docker
Swift on Docker
 
ES2015のカバレッジ計測
ES2015のカバレッジ計測ES2015のカバレッジ計測
ES2015のカバレッジ計測
 
CSSのカバレッジツール
CSSのカバレッジツールCSSのカバレッジツール
CSSのカバレッジツール
 
本当にあった怖い話 7つの幽霊 7つの成仏
本当にあった怖い話 7つの幽霊 7つの成仏本当にあった怖い話 7つの幽霊 7つの成仏
本当にあった怖い話 7つの幽霊 7つの成仏
 
Awsでwindowsゲームを動かす
Awsでwindowsゲームを動かすAwsでwindowsゲームを動かす
Awsでwindowsゲームを動かす
 
Action pack variantsの話
Action pack variantsの話Action pack variantsの話
Action pack variantsの話
 
LT_Gitのfast fowardと継続的デリバリー
LT_Gitのfast fowardと継続的デリバリーLT_Gitのfast fowardと継続的デリバリー
LT_Gitのfast fowardと継続的デリバリー
 
バージョン管理とGit
バージョン管理とGitバージョン管理とGit
バージョン管理とGit
 
Git天空闘技場_ハンズオン
Git天空闘技場_ハンズオンGit天空闘技場_ハンズオン
Git天空闘技場_ハンズオン
 
DVCSとGitの基礎
DVCSとGitの基礎DVCSとGitの基礎
DVCSとGitの基礎
 
20101001 5分でわかるtrac pluginの作り方_slideshare
20101001 5分でわかるtrac pluginの作り方_slideshare20101001 5分でわかるtrac pluginの作り方_slideshare
20101001 5分でわかるtrac pluginの作り方_slideshare
 

Recently uploaded

₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...Diya Sharma
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)Damian Radcliffe
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Roomgirls4nights
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts servicesonalikaur4
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersDamian Radcliffe
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024APNIC
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Roomdivyansh0kumar0
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Servicesexy call girls service in goa
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Roomdivyansh0kumar0
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girlsstephieert
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girladitipandeya
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkataanamikaraghav4
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Delhi Call girls
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 

Recently uploaded (20)

₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
₹5.5k {Cash Payment}New Friends Colony Call Girls In [Delhi NIHARIKA] 🔝|97111...
 
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Pratap Nagar Delhi 💯Call Us 🔝8264348440🔝
 
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 26 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)How is AI changing journalism? (v. April 2024)
How is AI changing journalism? (v. April 2024)
 
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With RoomVIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
VIP Kolkata Call Girls Salt Lake 8250192130 Available With Room
 
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls KolkataLow Rate Call Girls Kolkata Avani 🤌  8250192130 🚀 Vip Call Girls Kolkata
Low Rate Call Girls Kolkata Avani 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts serviceChennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
Chennai Call Girls Porur Phone 🍆 8250192130 👅 celebrity escorts service
 
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providersMoving Beyond Twitter/X and Facebook - Social Media for local news providers
Moving Beyond Twitter/X and Facebook - Social Media for local news providers
 
On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024On Starlink, presented by Geoff Huston at NZNOG 2024
On Starlink, presented by Geoff Huston at NZNOG 2024
 
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130  Available With RoomVIP Kolkata Call Girl Kestopur 👉 8250192130  Available With Room
VIP Kolkata Call Girl Kestopur 👉 8250192130 Available With Room
 
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine ServiceHot Service (+9316020077 ) Goa  Call Girls Real Photos and Genuine Service
Hot Service (+9316020077 ) Goa Call Girls Real Photos and Genuine Service
 
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Saket Delhi 💯Call Us 🔝8264348440🔝
 
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
Call Girls In Model Towh Delhi 💯Call Us 🔝8264348440🔝
 
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With RoomVIP Kolkata Call Girl Dum Dum 👉 8250192130  Available With Room
VIP Kolkata Call Girl Dum Dum 👉 8250192130 Available With Room
 
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No AdvanceRohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
Rohini Sector 22 Call Girls Delhi 9999965857 @Sabina Saikh No Advance
 
Russian Call girls in Dubai +971563133746 Dubai Call girls
Russian  Call girls in Dubai +971563133746 Dubai  Call girlsRussian  Call girls in Dubai +971563133746 Dubai  Call girls
Russian Call girls in Dubai +971563133746 Dubai Call girls
 
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call GirlVIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
VIP 7001035870 Find & Meet Hyderabad Call Girls LB Nagar high-profile Call Girl
 
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls KolkataVIP Call Girls Kolkata Ananya 🤌  8250192130 🚀 Vip Call Girls Kolkata
VIP Call Girls Kolkata Ananya 🤌 8250192130 🚀 Vip Call Girls Kolkata
 
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
Best VIP Call Girls Noida Sector 75 Call Me: 8448380779
 
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Rohini 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 

Search Form for Rails

  • 1. Search Form for Rails Roppongi.rb #11 2019/06/20(木) 1
  • 2. 自己紹介 名前: 神速 GitHub: @sinsoku (アイコン右上) Twitter: @sinsoku_listy (アイコン右下) Rails歴: それなり 2
  • 3. Searching 1. Elasticsearch 2. Amazon CloudSearch 3. Ransack 4. self implementation 5. other...? 3
  • 4. 4
  • 5. controller def index @q = Person.ransack(params[:q]) @people = @q.result(distinct: true) end 5
  • 6. view <%= search_form_for @q do |f| %> # Search if the name field contains... <%= f.label :name_cont %> <%= f.search_field :name_cont %> # Search if an associated articles.title starts with... <%= f.label :articles_title_start %> <%= f.search_field :articles_title_start %> # Attributes may be chained. Search multiple attributes for one value... <%= f.label :name_or_description_or_email_or_articles_title_cont %> <%= f.search_field :name_or_description_or_email_or_articles_title_cont %> <%= f.submit %> <% end %> 6
  • 7. Pros • easy to introduce • realizes complex conditions with Advanced Mode • searches by associations • used by many people(, and easy to find references) 7
  • 8. Cons • includes many hack codes for ActiveRecord • difficult to maintenance • CI failed on 5-2-stable ! • I do not like the design about Authorization 8
  • 9. Example Support for Rails 6 https://github.com/activerecord-hackery/ransack/pull/1027 9
  • 10. I came up with a new implementation So, I am developing a gem to replace Ransack. 10
  • 11. sinsoku/pickel Pickel provides methods that make it easy to build a search form for your Rails app. 11
  • 12. in controller def index search_params = Pickel.permit(params, :name, :age_gt, :posts_title_start) @search = Pickel.search(User, search_params) @users = @search.result end 12
  • 13. in view <%= form_for @search do |f| %> <%# Search records contains the value %> <%= f.label :name_cont %> <%= f.search_field :name_cont %> <%# Search records grater than the value %> <%= f.label :age_gt %> <%= f.number_field :age_gt %> <%# Search records an associated posts.title starts with the value %> <%= f.label :posts_title_start %> <%= f.search_field :posts_title_start %> <%= f.submit %> <% end %> 13
  • 14. Concept (Difference from Ransack) • refrains hack for ActiveRecord • basically builds a SQL in ActiveRecord.merge • (However, Arel is used) • allows search conditions by the StrongParameter • uses form_for as it is 14
  • 15. Design 1 • handle search conditions with Hash conditinos = { name_eq: 'foo', posts_title_start: 'bar' } 15
  • 16. Design 2 • Convert a condition to Relation rel_1 = User.where(name: 'foo') cond = Post.arel_table[:title].start('bar%') rel_2 = User.joins(:posts).merge(Post.where(cond)) 16
  • 17. Design 3 • Merge all conditions rel = rel_1.merge(rel_2) 17
  • 18. Is this usable in production? 18
  • 19. Sorry, it is still in development. Once it has been implemented to replace Ransack, I will be tagged v1.0.0. 19