[logaling-commit] logaling/logaling-server [master] Create user glossary

Back to archive index

SUZUKI Miho null+****@clear*****
Fri Sep 7 15:35:34 JST 2012


SUZUKI Miho	2012-09-07 15:35:34 +0900 (Fri, 07 Sep 2012)

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

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

  Log:
    Create user glossary

  Added files:
    app/views/user_glossaries/_form.html.haml
    app/views/user_glossaries/show.html.haml
  Modified files:
    app/controllers/user_glossaries_controller.rb
    app/views/dashboard/show.html.haml
    app/views/user_glossaries/new.html.haml
    config/routes.rb

  Modified: app/controllers/user_glossaries_controller.rb (+41 -0)
===================================================================
--- app/controllers/user_glossaries_controller.rb    2012-09-07 15:25:35 +0900 (9b46803)
+++ app/controllers/user_glossaries_controller.rb    2012-09-07 15:35:34 +0900 (47fa180)
@@ -1,4 +1,45 @@
 class UserGlossariesController < ApplicationController
+  before_filter :set_user
+  before_filter :set_user_glossary, :only => :create
+
+  # GET /user_glossaries/1
+  # GET /user_glossaries/1.json
+  def show
+  end
+
+  # GET /user_glossaries/new
+  # GET /user_glossaries/new.json
   def new
+    @user_glossary = UserGlossary.new()
+
+    respond_to do |format|
+      format.html
+      format.json { render json: @user_glossary }
+    end
+  end
+
+  # POST /user_glossaries
+  # POST /user_glossaries.json
+  def create
+    #TODO: check user_id
+    #TODO: do loga new --personal
+    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
+  end
+
+  private
+  def set_user
+    @user = current_user
+  end
+
+  def set_user_glossary
+    @user_glossary =****@user*****_glossaries.build(params[:user_glossary])
   end
 end

  Modified: app/views/dashboard/show.html.haml (+1 -1)
===================================================================
--- app/views/dashboard/show.html.haml    2012-09-07 15:25:35 +0900 (02d74d7)
+++ app/views/dashboard/show.html.haml    2012-09-07 15:35:34 +0900 (0013540)
@@ -1,2 +1,2 @@
 .well
-  %p= link_to "Create personal glossary", new_user_glossary_path(:id => current_user)
+  %p= link_to "Create user glossary", new_user_glossary_path(:user_id => current_user)

  Added: app/views/user_glossaries/_form.html.haml (+18 -0) 100644
===================================================================
--- /dev/null
+++ app/views/user_glossaries/_form.html.haml    2012-09-07 15:35:34 +0900 (4e4dad7)
@@ -0,0 +1,18 @@
+= form_for @user_glossary, :url => create_user_glossary_path do |f|
+  -if @user_glossary.errors.any?
+    #error_explanation
+      %h2= "#{pluralize(@user_glossary.errors.count, "error")} prohibited this user_glossary from being saved:"
+      %ul
+        - @user_glossary.errors.full_messages.each do |msg|
+          %li= msg
+
+  .well
+    %p Glossary name:
+    = f.text_field :name
+    %p Source language:
+    = f.text_field :source_language
+    %p Target language:
+    = f.text_field :target_language
+
+  .actions
+    = f.submit 'Save', :class => 'btn btn-primary'

  Modified: app/views/user_glossaries/new.html.haml (+2 -2)
===================================================================
--- app/views/user_glossaries/new.html.haml    2012-09-07 15:25:35 +0900 (d2aff9f)
+++ app/views/user_glossaries/new.html.haml    2012-09-07 15:35:34 +0900 (4ce4ae1)
@@ -1,2 +1,2 @@
-%h1 UserGlossary#new
-%p Find me in app/views/user_glossary/new.html.haml
\ No newline at end of file
+%h1 New UserGlossary
+= render 'form'

  Added: app/views/user_glossaries/show.html.haml (+1 -0) 100644
===================================================================
--- /dev/null
+++ app/views/user_glossaries/show.html.haml    2012-09-07 15:35:34 +0900 (51a7539)
@@ -0,0 +1 @@
+UserGlossary#show

  Modified: config/routes.rb (+5 -3)
===================================================================
--- config/routes.rb    2012-09-07 15:25:35 +0900 (682ee8a)
+++ config/routes.rb    2012-09-07 15:35:34 +0900 (d0617ce)
@@ -1,6 +1,4 @@
 LogalingServer::Application.routes.draw do
-  get "user_glossary/new"
-
   get "search", :as => :search, :controller => 'search', :action => :index
 
   get "top/index"
@@ -14,11 +12,15 @@ LogalingServer::Application.routes.draw do
               :only => :show
   end
 
+  resources :user_glossaries,
+    :path => 'users/:user_id/glossaries',
+    :constraints => {:id => %r{[^-]+-[^-]+}},
+    :only => [:new, :create, :show]
+
   match '/auth/:provider/callback', to: 'sessions#create'
   match '/auth/failure', to: 'sessions#failure'
   match "/signout" => "sessions#destroy", :as => :signout
   match "/dashboard" => "dashboard#show", :as => :dashboard
-  match "/users/:id/glossaries/new" => "user_glossaries#new", :as => :new_user_glossary
 
   root :to => 'top#index'
 end
-------------- next part --------------
An HTML attachment was scrubbed...
Télécharger 



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