[logaling-commit] logaling/logaling-server [master] Create personal project after creating UserGlossary record

Back to archive index

SHIMADA Koji null+****@clear*****
Mon Sep 10 15:34:17 JST 2012


SHIMADA Koji	2012-09-10 15:34:17 +0900 (Mon, 10 Sep 2012)

  New Revision: 388f35ca64c90f7ed478b6289196d21a36676034
  https://github.com/logaling/logaling-server/commit/388f35ca64c90f7ed478b6289196d21a36676034

  Merged c5d082c: Merge pull request #13 from logaling/enable-creating-user-glossary

  Log:
    Create personal project after creating UserGlossary record

  Modified files:
    app/controllers/user_glossaries_controller.rb
    app/models/user_glossary.rb

  Modified: app/controllers/user_glossaries_controller.rb (+10 -10)
===================================================================
--- app/controllers/user_glossaries_controller.rb    2012-09-10 15:21:52 +0900 (370f2ad)
+++ app/controllers/user_glossaries_controller.rb    2012-09-10 15:34:17 +0900 (f11128c)
@@ -23,16 +23,16 @@ class UserGlossariesController < ApplicationController
   # POST /user_glossaries.json
   def create
     @user_glossary = current_user.user_glossaries.build(params[:user_glossary])
-    if @user_glossary.create
-      respond_to do |format|
-        if @user_glossary.save
-          format.html { render action: "show", notice: 'User glossary was successfully created.' }
-          format.json { render json: @user_glossary, status: :created, location: @user_glossary }
-        else
-          format.html { render action: "new" }
-          format.json { render json: @user_glossary.errors, status: :unprocessable_entity }
-        end
-      end
+    @user_glossary.save!
+
+    respond_to do |format|
+      format.html { render action: "show", notice: 'User glossary was successfully created.' }
+      format.json { render json: @user_glossary, status: :created, location: @user_glossary }
+    end
+  rescue => e
+    respond_to do |format|
+      format.html { render action: "new" }
+      format.json { render json: @user_glossary.errors, status: :unprocessable_entity }
     end
   end
 

  Modified: app/models/user_glossary.rb (+4 -9)
===================================================================
--- app/models/user_glossary.rb    2012-09-10 15:21:52 +0900 (4180840)
+++ app/models/user_glossary.rb    2012-09-10 15:34:17 +0900 (da83df6)
@@ -4,18 +4,13 @@ class UserGlossary < ActiveRecord::Base
   belongs_to :user
 
   #TODO: validation
+  after_create :create_personal_project!
 
-  def create
-    #TODO: check dupplication
-    begin
-      personal_project = LogalingServer.repository.create_personal_project(glossary_name, source_language, target_language)
-    rescue Logaling::GlossaryAlreadyRegistered
-      false
-    end
-    true
+  private
+  def create_personal_project!
+    LogalingServer.repository.create_personal_project(glossary_name, source_language, target_language)
   end
 
-  private
   def glossary_name
     "%05d-%s"%[self.user_id, name]
   end
-------------- next part --------------
An HTML attachment was scrubbed...
Télécharger 



More information about the logaling-commit mailing list
Back to archive index