[logaling-commit] logaling/logaling-server [prioritize-the-search] Use UserConfig.id as parameter

Zurück zum Archiv-Index

SUZUKI Miho null+****@clear*****
Tue Sep 25 15:22:01 JST 2012


SUZUKI Miho	2012-09-25 15:22:01 +0900 (Tue, 25 Sep 2012)

  New Revision: 2707de7082bb2eb5acbe34faa90605d75baf5458
  https://github.com/logaling/logaling-server/commit/2707de7082bb2eb5acbe34faa90605d75baf5458

  Log:
    Use UserConfig.id as parameter

  Modified files:
    app/controllers/user_configs_controller.rb
    app/models/user_config.rb
    app/views/dashboard/show.html.haml
    config/routes.rb

  Modified: app/controllers/user_configs_controller.rb (+17 -3)
===================================================================
--- app/controllers/user_configs_controller.rb    2012-09-24 16:36:41 +0900 (f0cb850)
+++ app/controllers/user_configs_controller.rb    2012-09-25 15:22:01 +0900 (67d07e7)
@@ -3,12 +3,26 @@ 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)
+  def create
+    user_config = UserConfig.new(params[:user_config])
+    user_config.user_id = params[:user_id]
     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
+
+  def update
+    user_config = UserConfig.find(params[:id])
+    if user_config.glossary_name == params[:user_config][:glossary_name] &&
+      user_config.source_language == params[:user_config][:source_language] &&
+      user_config.target_language == params[:user_config][:target_language]
+      user_config.destroy
+      redirect_to dashboard_path, notice: 'User config was successfully unset.'
+    elsif user_config.update_attributes!(params[:user_config])
+      redirect_to dashboard_path, notice: 'User config was successfully update.'
+    end
+  rescue => e
+    redirect_to dashboard_path, notice: 'User config setting was failed.'
+  end
 end

  Modified: app/models/user_config.rb (+0 -5)
===================================================================
--- app/models/user_config.rb    2012-09-24 16:36:41 +0900 (66d9be9)
+++ app/models/user_config.rb    2012-09-25 15:22:01 +0900 (d99cbdc)
@@ -5,11 +5,6 @@ class UserConfig < ActiveRecord::Base
 
   belongs_to :user
 
-  def set_config(params)
-    self.user_id ||= params[:user_id]
-    self.glossary_name, self.source_language, self.target_language = id_to_config(params[:id])
-  end
-
   def same?(user_glossary)
     glossary_name == user_glossary.glossary_name &&
     source_language == user_glossary.source_language &&

  Modified: app/views/dashboard/show.html.haml (+13 -2)
===================================================================
--- app/views/dashboard/show.html.haml    2012-09-24 16:36:41 +0900 (698bd3d)
+++ app/views/dashboard/show.html.haml    2012-09-25 15:22:01 +0900 (ba7cda4)
@@ -5,9 +5,20 @@
     %ul
       - @user_glossaries.each do |user_glossary|
         %li
-          - mark = @user_config.same?(user_glossary) ? "★": "☆"
+          - mark = @user_config.same?(user_glossary) ? "★" : "☆"
           = user_glossary.glossary_name
           = user_glossary.source_language
           = user_glossary.target_language
           = link_to "Show", user_glossary_path(current_user, user_glossary)
-          = link_to mark, user_config_path(current_user, user_glossary.config_key), method: :put
+          - unless @user_config.id.present?
+            = form_for @user_config, url: user_configs_path(current_user), method: :post do |f|
+              = hidden_field :user_config, :glossary_name, value: user_glossary.glossary_name
+              = hidden_field :user_config, :source_language, value: user_glossary.source_language
+              = hidden_field :user_config, :target_language, value: user_glossary.target_language
+              = f.submit mark, :class => 'btn btn-link'
+          - else
+            = form_for @user_config, url: user_config_path(current_user, @user_config), method: :put do |f|
+              = hidden_field :user_config, :glossary_name, value: user_glossary.glossary_name
+              = hidden_field :user_config, :source_language, value: user_glossary.source_language
+              = hidden_field :user_config, :target_language, value: user_glossary.target_language
+              = f.submit mark, :class => 'btn btn-link'

  Modified: config/routes.rb (+0 -1)
===================================================================
--- config/routes.rb    2012-09-24 16:36:41 +0900 (740e39e)
+++ config/routes.rb    2012-09-25 15:22:01 +0900 (8036f2b)
@@ -21,7 +21,6 @@ LogalingServer::Application.routes.draw do
     end
     resources :user_configs,
       :path => 'configs',
-      :constraints => {:id => %r{[^\.]+\.[^\.]+\.[^\.]+}},
       :as => :configs
   end
 
-------------- next part --------------
An HTML attachment was scrubbed...
Download 



More information about the logaling-commit mailing list
Zurück zum Archiv-Index