SHIMADA Koji
null+****@clear*****
Tue Oct 9 22:46:29 JST 2012
SHIMADA Koji 2012-10-09 22:46:29 +0900 (Tue, 09 Oct 2012) New Revision: f82b4233c043e9a66ff3b864fcde2991a72c1085 https://github.com/logaling/logaling-server/commit/f82b4233c043e9a66ff3b864fcde2991a72c1085 Log: Move method: UserGlossary.of to User#find_glossary Modified files: app/controllers/terms_controller.rb app/controllers/user_glossaries_controller.rb app/models/user.rb app/models/user_glossary.rb Modified: app/controllers/terms_controller.rb (+1 -1) =================================================================== --- app/controllers/terms_controller.rb 2012-10-09 22:43:37 +0900 (ab5d993) +++ app/controllers/terms_controller.rb 2012-10-09 22:46:29 +0900 (d024481) @@ -41,7 +41,7 @@ class TermsController < ApplicationController private def set_user_glossary - @user_glossary = UserGlossary.of(params[:glossary_id], current_user) + @user_glossary = current_user.find_glossary(params[:glossary_id]) rescue ActiveRecord::RecordNotFound render :file => 'public/404.html', :status => 404, :layout => false end Modified: app/controllers/user_glossaries_controller.rb (+2 -2) =================================================================== --- app/controllers/user_glossaries_controller.rb 2012-10-09 22:43:37 +0900 (8ab1fd7) +++ app/controllers/user_glossaries_controller.rb 2012-10-09 22:46:29 +0900 (9c85ab2) @@ -7,7 +7,7 @@ class UserGlossariesController < ApplicationController def show @user = User.find_by_name(params[:user_id]) @term = GlossaryEntry.new - @user_glossary = UserGlossary.of(params[:id], @user) + @user_glossary =****@user*****_glossary(params[:id]) @registered_terms = Kaminari.paginate_array(@user_glossary.terms).page(params[:page]) rescue ActiveRecord::RecordNotFound render :file => 'public/404.html', :status => 404, :layout => false @@ -34,7 +34,7 @@ class UserGlossariesController < ApplicationController # DELETE /user_glossaries/1 def destroy user = User.find_by_name(params[:user_id]) - @user_glossary = UserGlossary.of(params[:id], user) + @user_glossary = user.find_glossary(params[:id]) @user_glossary.destroy redirect_to dashboard_path, notice: 'User glossary was successfully destroyed.' rescue Logaling::CommandFailed, Logaling::GlossaryNotFound => e Modified: app/models/user.rb (+10 -0) =================================================================== --- app/models/user.rb 2012-10-09 22:43:37 +0900 (90b1c06) +++ app/models/user.rb 2012-10-09 22:46:29 +0900 (12c1da8) @@ -33,4 +33,14 @@ class User < ActiveRecord::Base def own?(user_glossary) user_glossaries.include?(user_glossary) end + + def find_glossary(glossary_id) + name, bilingualr_pair = glossary_id.split('/', 2) + source_language, target_language = bilingualr_pair.split('-', 2) + glossary = user_glossaries.with_name(name).of_bilingualr_pair(source_language, target_language).first + unless glossary + raise ActiveRecord::RecordNotFound + end + glossary + end end Modified: app/models/user_glossary.rb (+0 -10) =================================================================== --- app/models/user_glossary.rb 2012-10-09 22:43:37 +0900 (d9d64e1) +++ app/models/user_glossary.rb 2012-10-09 22:46:29 +0900 (6f74a6f) @@ -1,16 +1,6 @@ #coding: utf-8 class UserGlossary < ActiveRecord::Base class << self - def of(id, user) - name, bilingualr_pair = id.split('/', 2) - source_language, target_language = bilingualr_pair.split('-', 2) - glossary = self.with_name(name).of_bilingualr_pair(source_language, target_language).where(user_id: user).first - unless glossary - raise ActiveRecord::RecordNotFound - end - glossary - end - def find_by_term_and_user(term, user) return nil unless term.owner?(user) user.user_glossaries.with_name(term.glossary_name_without_user_id) -------------- next part -------------- An HTML attachment was scrubbed...Download