現在Rubyで検索条件の設定を行っております。
検索条件には、
・一定期間を検索
(ex.2016/11/01~2017/09/01を検索)
・更新回数を検索
(1:nの関係において、nが登録された回数を指定した検索)
を搭載したく考えておりますが、まだrubyが未熟な部分もあり、わかりかねております。
(おそらくviewの設定のみかと思うのですが。)
どなたか教えて頂けると幸いです。
よろしくお願い致します。
post_controller.rb
1 def index 2 @q = Post.ransack(params[:q]) 3 @posts = @q.result.page(params[:page]).per(100) 4 end 5
index.html.erb
1<%= search_form_for @q do |f| %> 2 <table width = "90%"> 3 <col width="20%"> 4 <col width="30%"> 5 <col width="20%"> 6 <col width="30%"> 7 <tbody> 8 <tr> 9 <th colspan = "4">検索</th> 10 </tr> 11 <tr> 12 <th>会社名</th> 13 <td><%= f.search_field :company_cont, type: "text" %></td> 14 <th>店舗名</th> 15 <td><%= f.search_field :store_cont, type: "text" %> </td> 16 </tr> 17 <tr> 18 <th>代表者</th> 19 <td><%= f.search_field :owner_cont, type: "text" %></td> 20 <th>ダイヒョウ</th> 21 <td><%= f.search_field :kana_cont, type: "text" %></td> 22 </tr> 23 <tr> 24 <th>電話番号1</th> 25 <td><%= f.search_field :tel_cont, type: "text" %></td> 26 <th>電話番号2</th> 27 <td><%= f.search_field :tel2_cont, type: "text" %></td> 28 </tr> 29 <tr> 30 <th>FAX番号</th> 31 <td><%= f.search_field :fax_cont, type: "text" %></td> 32 <th>業種</th> 33 <td><%= f.search_field :industry_cont, type: "text" %></td> 34 </tr> 35 <tr> 36 <th>メール</th> 37 <td><%= f.search_field :mail_cont, type: "text" %></td> 38 <th>URL</th> 39 <td><%= f.search_field :url_cont, type: "text" %></td> 40 </tr> 41 <tr> 42 <th>人数</th> 43 <td><%= f.search_field :people_cont, type: "text" %></td> 44 <th>住所</th> 45 <td><%= f.search_field :address_cont, type: "text" %></td> 46 </tr> 47 <tr> 48 <th>期間</th> 49 <td><%= f.search_field :updated_at_gteq, type: "date" %></td> 50 <th>期間</th> 51 <td><%= f.search_field :updated_at_lteq, type: "date" %></td> 52 </tr> 53 <tr> 54 <th colspan = "4" ><%= f.submit '検索' %></th> 55 </tr> 56 <% end %> 57 </tbody> 58 </table> 59 60</br> 61<div class="heading"><h2>コールリスト</h2></div> 62 <table width ="90%"> 63 <tbody> 64 <col width="30%"> 65 <col width="17%"> 66 <col width="18%"> 67 <col width="25%"> 68 <col width="10%"> 69 <tr> 70 <th>会社名</th> 71 <th>代表者名</th> 72 <th>電話番号</th> 73 <th>最終更新日</th> 74 <th>編集/削除</th> 75 </tr> 76 <% @posts.each do |post| %> 77 <tr> 78 <td><%= link_to post.company, post_path(post) %> </td> 79 <td><%= link_to post.owner, post_path(post) %></td> 80 <td><%= post.tel %></td> 81 <td><%= post.details.order('updated_at DESC').first.try(:updated_at) %></td> 82 <td><%= link_to '編集', edit_post_path(post), class: 'command'%> 83 <%= link_to '削除', 84 post_path(post), 85 method: :delete, 86 class: 'command', 87 data: { confirm: '本当に削除しますか?'} %></td> 88 <% end %> 89 </tr> 90 <tr> 91 <th colspan = "5"> 92 前のページ<%= paginate @posts %>次のページ 93 </th> 94 </tr> 95 </tbody> 96 </table>
model.rb
1 2 def self.updatable_attributes 3 ["company", "store", "owner","kana", "tel", "tel2","fax", "industry", "address", "mail", "url", "people", "history"] 4 end 5
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2018/11/29 15:32