2 class WordsController < ApplicationController
8 @word = Word.find params[:id]
9 @section_count = SectionWord.count(:conditions => ['word_id = ?', @word.id]).to_i
10 @section_sum = SectionWord.sum(:count, :conditions => ['word_id = ?', @word.id]).to_i
11 @sections = Section.find(:all, :include => :section_words,
12 :conditions => ['section_words.word_id = ?', @word.id]
20 render :action => 'list'
23 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
24 verify :method => :post, :only => [ :destroy, :create, :update, :upload_word, :remove_word ],
25 :redirect_to => { :action => :list }
28 @page = params[:page].to_i
29 @page = 1 if @page < 1
30 @search = params[:search]
31 @filter = params[:filter].to_s.to_i
33 @words = Word.find(:all, :include => 'hateda_word',
34 :conditions => ['hateda_words.upload_at is null or words.update_at > hateda_words.upload_at']
38 ['letter = ?', @search]
42 @paginate, @words = paginate(:words, :conditions => cond,
43 :order => 'count desc', :per_page => 20
47 render :template => '/hateda/word_list'
61 @word = Word.new(params[:word])
64 flash[:notice] = '登録しました'
65 redirect_to :action => :edit, :id => @word.id
67 render :action => 'new'
72 @word = Word.find params[:id]
73 @section_count = SectionWord.count(:conditions => ['word_id = ?', @word.id]).to_i
74 @section_sum = SectionWord.sum(:count, :conditions => ['word_id = ?', @word.id]).to_i
75 @sections = Section.find(:all, :include => :section_words,
76 :conditions => ['section_words.word_id = ?', @word.id]
78 @word.detail = @word.edit_detail
82 @word = Word.find(params[:id])
83 if @word.update_attributes(params[:word])
85 render :action => 'show', :id => @word.id
87 render :action => 'edit'
92 Word.find(params[:id]).destroy
93 redirect_to :action => 'list'
97 @word = Word.find params[:id]
98 HatedaWord.upload_one @user, @pass, @word.id
100 render :action => :show, :id => @word.id
104 htn = Hatena.new(@user, @pass)
105 @word = Word.find params[:id]
106 HatedaWord.remove_one htn, @word.id
108 render :action => :show, :id => @word.id
114 if (f = params[:browse][:file]).respond_to?(:read)
115 if f.size > 2.megabytes
116 e = 'ファイルサイズが2MBを超えています'
121 e = 'ファイルを受け取れませんでした'
124 flash[:error] = 'インポートできませんでした'
125 flash[:txt_error] = e
126 redirect_to :controller => '/section', :action => :index
128 redirect_to :controller => '/section', :action => :index
133 send_data(Word.export, :filename => "word.txt")