OSDN Git Service

一覧と削除を実装
authorshimada <cake@users.sourceforge.co.jp>
Thu, 21 Oct 2010 02:36:37 +0000 (11:36 +0900)
committershimada <cake@users.sourceforge.co.jp>
Thu, 21 Oct 2010 02:36:37 +0000 (11:36 +0900)
.gitignore [new file with mode: 0644]
app/controllers/songs_controller.rb
app/models/song.rb
app/views/songs/list.html.erb [new file with mode: 0644]

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..a01ee28
--- /dev/null
@@ -0,0 +1 @@
+.*.swp
index 35c6b3a..b96c918 100644 (file)
@@ -38,8 +38,18 @@ class SongsController < BaseController
     return redirect_to :action => :edit
   end
 
+  def destroy
+    @song = Song.find(params[:id])
+    @song.destroy
+    redirect_to song_url
+  end
+
   def list
-    @songs = Song.active.all
+    if params[:letter]
+      @songs = Song.active.begin_with(params[:letter])
+    else
+      @songs = Song.active.all
+    end
   end
 
   def search
index 34118e1..ec5c797 100644 (file)
@@ -26,8 +26,12 @@ class Song < ActiveRecord::Base
     font_size_id_by_key(:middle)
   end
 
+  def self.begin_with(letter)
+    self.find(:all, :conditions => ["words_for_search LIKE ?", letter + '%'], :order => "id")
+  end
+
   def make_words_for_search
-    words_for_search = words + kana
+    words_for_search = kana + words
   end
 
   def kana
diff --git a/app/views/songs/list.html.erb b/app/views/songs/list.html.erb
new file mode 100644 (file)
index 0000000..612592e
--- /dev/null
@@ -0,0 +1,25 @@
+<table border=1>
+  <tr>
+    <th nowrap>ID</th>
+    <th nowrap>CODE<br>コード</th>
+    <th nowrap>SIZE<br>サイズ</th>
+    <th>TITLE<br>タイトル</th>
+    <th nowrap>LAST UPDATE<br>最終更新</th>
+    <th nowrap colspan="3">OPERATIONS<br>各種操作</th>
+  </tr>
+  <%- @songs.each do |song| -%>
+    <tr>
+      <td><%=h song.id %></td>
+      <td><%=h song.code %></td>
+      <td><%=h song.font_size_name %></td>
+      <td><%=h song.title %></td>
+      <td><%=l song.updated_at %></td>
+      <td>
+        <%= link_to('EDIT', edit_song_path(song)) %>
+        <%= link_to('DEL', song, :confirm => '本当に削除しますか?', :method => :delete) %>
+        <%= link_to('PDF') %>
+        <%= link_to('MP3') %>
+      </td>
+    </tr>
+  <%- end -%>
+</table>