Class: NameTranslationsController
- Inherits:
- 
      ApplicationController
      
        - Object
- ActionController::Base
- ApplicationController
- NameTranslationsController
 
- Defined in:
- app/controllers/name_translations_controller.rb
Overview
The name translations controller.
Instance Method Summary (collapse)
- 
  
    
      - (Object) create 
    
    
  
  
  
  
  
  
  
  
  
    POST /name_translations POST /name_translations.json. 
- 
  
    
      - (Object) destroy 
    
    
  
  
  
  
  
  
  
  
  
    DELETE /name_translations/1 DELETE /name_translations/1.json. 
- 
  
    
      - (Object) edit 
    
    
  
  
  
  
  
  
  
  
  
    GET /name_translations/1/edit. 
- 
  
    
      - (Object) index 
    
    
  
  
  
  
  
  
  
  
  
    GET /name_translations GET /name_translations.json. 
- 
  
    
      - (Object) new 
    
    
  
  
  
  
  
  
  
  
  
    GET /name_translations/new. 
- 
  
    
      - (Object) show 
    
    
  
  
  
  
  
  
  
  
  
    GET /name_translations/1 GET /name_translations/1.json. 
- 
  
    
      - (Object) update 
    
    
  
  
  
  
  
  
  
  
  
    PATCH/PUT /name_translations/1 PATCH/PUT /name_translations/1.json. 
Instance Method Details
- (Object) create
POST /name_translations POST /name_translations.json
| 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | # File 'app/controllers/name_translations_controller.rb', line 49 def create @translation_langs = TranslationsHelper.supported_language_codes_with_names @editTagForm = false @tag_id = params['name_translation']['tag_id'] result = false unless @tag_id.nil? tag = Tag.find_by_id(@tag_id) @name_translation = NameTranslation.new(name_translation_params) # if there is no original name set this one as original name if tag.original_name.nil? lang_code = params[:name_translation][:lang_code].to_s text = params[:name_translation][:text].to_s unless lang_code.empty? or text.empty? @name_translation = NameTranslation.new(text: text, lang_code: lang_code) result = @name_translation.save end if result tag.original_name = @name_translation end else original_text = tag.original_name.text original_lang_code = tag.original_name.lang_code new_lang_code = params[:name_translation][:lang_code].to_s unless new_lang_code.nil? or new_lang_code.empty? new_text = translate_text(original_text, original_lang_code, new_lang_code) @name_translation = NameTranslation.new(text: new_text, lang_code: new_lang_code) result = @name_translation.save if result tag.name_translations << @name_translation end end end end respond_to do |format| if result format.html { redirect_to tag_path(@tag_id), notice: 'Name translation was successfully created.' } format.json { render :show, status: :created, location: @name_translation } else format.html { redirect_to new_name_translation_path(:mode => 'in_mode', :tag_id => @tag_id) } format.json { render json: @name_translation.errors, status: :unprocessable_entity } end end end | 
- (Object) destroy
DELETE /name_translations/1 DELETE /name_translations/1.json
| 121 122 123 124 125 126 127 128 129 | # File 'app/controllers/name_translations_controller.rb', line 121 def destroy tag_id = params['tag_id'] @name_translation.destroy respond_to do |format| format.html { redirect_to tag_path(tag_id), notice: 'Name translation was successfully destroyed.' } format.json { head :no_content } end end | 
- (Object) edit
GET /name_translations/1/edit
| 41 42 43 44 45 | # File 'app/controllers/name_translations_controller.rb', line 41 def edit @tag_id = params['tag_id'] @translation_langs = TranslationsHelper.supported_language_codes_with_names @editTagForm = true end | 
- (Object) index
GET /name_translations GET /name_translations.json
| 9 10 11 12 13 14 15 16 | # File 'app/controllers/name_translations_controller.rb', line 9 def index if current_customer.role = 'admin' @name_translations = NameTranslation.all else #output customers name translations @name_translations = NameTranslation.joins(:tag).where('Tags.customer_id' => current_customer) end end | 
- (Object) new
GET /name_translations/new
| 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | # File 'app/controllers/name_translations_controller.rb', line 24 def new @name_translation = NameTranslation.new @tag_id = params['tag_id'] @translation_langs = TranslationsHelper.supported_language_codes_with_names @editTagForm = false # if this is the first name set it as original name and show a text field unless @tag_id.nil? tag = Tag.find_by_id(@tag_id) if tag.original_name.nil? @editTagForm = true end end end | 
- (Object) show
GET /name_translations/1 GET /name_translations/1.json
| 20 21 | # File 'app/controllers/name_translations_controller.rb', line 20 def show end | 
- (Object) update
PATCH/PUT /name_translations/1 PATCH/PUT /name_translations/1.json
| 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | # File 'app/controllers/name_translations_controller.rb', line 104 def update @tag_id = params['name_translation']['tag_id'] @editTagForm = true respond_to do |format| if @name_translation.update(name_translation_params) format.html { redirect_to tag_path(@tag_id), notice: 'Name translation was successfully updated.' } format.json { render :show, status: :ok, location: @name_translation } else format.html { render :edit } format.json { render json: @name_translation.errors, status: :unprocessable_entity } end end end |