SUZUKI Miho
null+****@clear*****
Fri Sep 21 18:56:05 JST 2012
SUZUKI Miho 2012-09-21 18:56:05 +0900 (Fri, 21 Sep 2012) New Revision: 7ea446a54b3475ce1175ac2fafbe0666803c15df https://github.com/logaling/logaling-server/commit/7ea446a54b3475ce1175ac2fafbe0666803c15df Merged 971b851: Merge pull request #14 from logaling/prioritize-the-search Log: Set user config for prioritize search Added files: app/controllers/user_configs_controller.rb Modified files: app/controllers/dashboard_controller.rb app/models/user_config.rb app/models/user_glossary.rb app/views/dashboard/show.html.haml config/routes.rb Modified: app/controllers/dashboard_controller.rb (+1 -0) =================================================================== --- app/controllers/dashboard_controller.rb 2012-09-21 15:11:14 +0900 (fb0a3bc) +++ app/controllers/dashboard_controller.rb 2012-09-21 18:56:05 +0900 (1574b3a) @@ -2,6 +2,7 @@ class DashboardController < ApplicationController before_filter :authenticate! def show + @user_config = UserConfig.new @user_glossaries = UserGlossary.find_all_by_user_id(current_user.id) end end Added: app/controllers/user_configs_controller.rb (+21 -0) 100644 =================================================================== --- /dev/null +++ app/controllers/user_configs_controller.rb 2012-09-21 18:56:05 +0900 (4222314) @@ -0,0 +1,21 @@ +#coding: utf-8 +class UserConfigsController < ApplicationController + before_filter :authenticate! + before_filter :valid_user? + + def update + user_config = UserConfig.find_by_user_id(params[:user_id]) || UserConfig.new + user_config.set_config(params) + user_config.save! + redirect_to dashboard_path, notice: 'User config was successfully set.' + rescue => e + redirect_to dashboard_path, notice: 'User config setting was failed.' + end + + private + def valid_user? + if current_user.id != params[:user_id].to_i + redirect_to dashboard_path, notice: "不正なアクセスです" + end + end +end Modified: app/models/user_config.rb (+13 -1) =================================================================== --- app/models/user_config.rb 2012-09-21 15:11:14 +0900 (235884e) +++ app/models/user_config.rb 2012-09-21 18:56:05 +0900 (b648288) @@ -1,5 +1,17 @@ class UserConfig < ActiveRecord::Base - attr_accessible :glossary, :source_language, :target_language + attr_accessible :glossary, :source_language, :target_language, :user_id + + validates_presence_of :glossary, :source_language, :target_language, :user_id belongs_to :user + + def set_config(params) + self.user_id ||= params[:user_id] + self.glossary, self.source_language, self.target_language = id_to_config(params[:id]) + end + + private + def id_to_config(id) + id.split(".", 3) + end end Modified: app/models/user_glossary.rb (+4 -0) =================================================================== --- app/models/user_glossary.rb 2012-09-21 15:11:14 +0900 (846b6eb) +++ app/models/user_glossary.rb 2012-09-21 18:56:05 +0900 (6fa2ad5) @@ -13,6 +13,10 @@ class UserGlossary < ActiveRecord::Base "%05d-%s" % [user_id, name] end + def to_param + "%s.%s.%s" % [name, source_language, target_language] + end + def add!(term) raise ArgumentError unless term.valid? Modified: app/views/dashboard/show.html.haml (+2 -2) =================================================================== --- app/views/dashboard/show.html.haml 2012-09-21 15:11:14 +0900 (ae7bbf4) +++ app/views/dashboard/show.html.haml 2012-09-21 18:56:05 +0900 (82b72d0) @@ -1,7 +1,6 @@ -%p#notice= notice - .well %p= link_to "Create user glossary", new_user_glossary_path(:user_id => current_user) + %p %ul - @user_glossaries.each do |user_glossary| @@ -10,3 +9,4 @@ = user_glossary.source_language = user_glossary.target_language = link_to "Show", user_glossary_path(current_user, user_glossary) + = link_to "☆", user_config_path(current_user, user_glossary.to_param), method: :put Modified: config/routes.rb (+4 -0) =================================================================== --- config/routes.rb 2012-09-21 15:11:14 +0900 (7857ccf) +++ config/routes.rb 2012-09-21 18:56:05 +0900 (740e39e) @@ -19,6 +19,10 @@ LogalingServer::Application.routes.draw do :as => :glossaries do resources :terms end + resources :user_configs, + :path => 'configs', + :constraints => {:id => %r{[^\.]+\.[^\.]+\.[^\.]+}}, + :as => :configs end match '/auth/:provider/callback', to: 'sessions#create' -------------- next part -------------- An HTML attachment was scrubbed... Download