Révision | edf3eb88ac109db298ef659bfee727ed286bd0ce (tree) |
---|---|
l'heure | 2013-04-04 22:16:44 |
Auteur | SHIMADA Keiki <shimada.cake@gmai...> |
Commiter | SHIMADA Keiki |
#10 スライド検索
@@ -2,6 +2,7 @@ class SlidesController < ApplicationController | ||
2 | 2 | # GET /slides |
3 | 3 | # GET /slides.json |
4 | 4 | def index |
5 | + @slide_search_form = SlideSearchForm.new(params[:slide_search_form]) | |
5 | 6 | @recents = Slide.recents |
6 | 7 | |
7 | 8 | respond_to do |format| |
@@ -89,4 +90,9 @@ class SlidesController < ApplicationController | ||
89 | 90 | format.json { head :no_content } |
90 | 91 | end |
91 | 92 | end |
93 | + | |
94 | + def search | |
95 | + @slide_search_form = SlideSearchForm.new(params[:slide_search_form]) | |
96 | + @slides = @slide_search_form.search.page(params[:page]) | |
97 | + end | |
92 | 98 | end |
@@ -116,10 +116,6 @@ class SongsController < ApplicationController | ||
116 | 116 | |
117 | 117 | def search |
118 | 118 | @song_search_form = SongSearchForm.new(params[:song_search_form]) |
119 | - if @song_search_form.q.present? | |
120 | - @songs = @song_search_form.search.page(params[:page]) | |
121 | - else | |
122 | - @songs = [] | |
123 | - end | |
119 | + @songs = @song_search_form.search.page(params[:page]) | |
124 | 120 | end |
125 | 121 | end |
@@ -0,0 +1,20 @@ | ||
1 | +class SlideSearchForm | |
2 | + extend ActiveModel::Naming | |
3 | + include ActiveModel::Conversion | |
4 | + | |
5 | + attr_accessor :q | |
6 | + | |
7 | + def initialize(params) | |
8 | + if params && params.has_key?(:q) | |
9 | + self.q = params[:q] | |
10 | + end | |
11 | + end | |
12 | + | |
13 | + def search | |
14 | + slides = Slide.arel_table | |
15 | + Slide.where(slides[:body].matches("%#{q}%")) | |
16 | + end | |
17 | + | |
18 | + private | |
19 | + def persisted?; false end | |
20 | +end | |
\ No newline at end of file |
@@ -1,6 +1,13 @@ | ||
1 | 1 | <%- title -%> |
2 | 2 | <h1>メッセージスライド</h1> |
3 | 3 | |
4 | +<%= form_for @slide_search_form, url: search_slides_path, html: {method: :get} do |f| %> | |
5 | +<p>検索 | |
6 | + <%= f.text_field :q, :size => '30' %> | |
7 | + <%= f.submit 'search' %> | |
8 | +</p> | |
9 | +<%- end -%> | |
10 | + | |
4 | 11 | <p><%= link_to '全スライド一覧', list_slides_path %></p> |
5 | 12 | |
6 | 13 | <h2>最近の更新(Recent changes)</h2> |
@@ -0,0 +1,10 @@ | ||
1 | +<%- title -%> | |
2 | +<%= form_for @slide_search_form, url: search_slides_path, html: {:method => :get} do |f| -%> | |
3 | + <p>検索 | |
4 | + <%= f.text_field :q, :size => '30' %> | |
5 | + <%= f.submit 'search' %> | |
6 | + </p> | |
7 | +<%- end -%> | |
8 | +<%= render :partial => 'list' %> | |
9 | + | |
10 | +<%= link_to 'Back', slides_path %> |
@@ -1,14 +1,15 @@ | ||
1 | 1 | <%- title -%> |
2 | 2 | <h1>PRAISE DATABASE</h1> |
3 | 3 | |
4 | -<%= form_for @song_search_form, :url => search_songs_path, :html => {:method => :get} do |f| -%> | |
4 | +<%= form_for @song_search_form, url: search_songs_path, html: {:method => :get} do |f| -%> | |
5 | 5 | <p>検索 |
6 | - <%= f.text_field :q, :size => "30" %> | |
7 | - <%= f.submit "search" %> | |
6 | + <%= f.text_field :q, :size => '30' %> | |
7 | + <%= f.submit 'search' %> | |
8 | 8 | </p> |
9 | - <p><%= link_to '全曲一覧', list_songs_path %></p> | |
10 | 9 | <%- end -%> |
11 | 10 | |
11 | +<p><%= link_to '全曲一覧', list_songs_path %></p> | |
12 | + | |
12 | 13 | <h2>最近の更新(Recent changes)</h2> |
13 | 14 | <%- if @recents.blank? -%> |
14 | 15 | <p>更新はありません</p> |
@@ -1,7 +1,7 @@ | ||
1 | 1 | <%- title -%> |
2 | 2 | <%= form_for @song_search_form, :url => search_songs_path, :html => {:method => :get} do |f| -%> |
3 | 3 | <p>検索 |
4 | - <%= f.select(:code, Song.code_options, :include_blank => true) %> | |
4 | + <%= f.select(:code, Song.code_options, :include_blank => 'コード') %> | |
5 | 5 | <%= f.text_field :q, :size => "30" %> |
6 | 6 | <%= f.submit "search" %> |
7 | 7 | </p> |
@@ -5,6 +5,7 @@ Ginmaku::Application.routes.draw do | ||
5 | 5 | end |
6 | 6 | |
7 | 7 | collection do |
8 | + get :search | |
8 | 9 | get :list |
9 | 10 | end |
10 | 11 | end |