Class: Aspartame::AspartameTranslatorController

Inherits:
ApplicationController show all
Defined in:
app/controllers/aspartame/aspartame_translator_controller.rb

Instance Method Summary collapse

Instance Method Details

#showObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/controllers/aspartame/aspartame_translator_controller.rb', line 6

def show
#    debugger

  # window.location.origin: "http://stackoverflow.com"
  # window.location.pathname: "/questions/406192/how-to-get-the-current-url-in-jquery"
  t = Aspartame::AspartameTranslation.where("language = ? AND source = ? AND url = ?", params[:language], params[:source], params[:url]).first
 #   debugger

  # if translation exist
  # if t then
    @translation = t.translation 
  # else
  #   # check if there exist a translation with any status
  #   c = Translation.where("language = ? AND phrase_source = ?", params[:language], params[:phrase_source]).first
    
  #   # create translation when not existing
  #   unless c then
  #     Translation.new(:url_origin => params[:url_origin],:url_pathname => params[:url_pathname], :language => params[:language],:phrase_source=>params[:phrase_source],:status=>1).save
  #     @translation = "~#{params[:phrase_source]}~"
  #   else
  #   @translation = "!#{params[:phrase_source]}!"
  #   end
  # end

  #    unless t.phrase

  #    @translation = params[:text].reverse

  #    Translation.new(:url => '', :language => params[:lanuage],:src=>params[:text],:status=>1).save
  #  else
  #    @translation = "~#{params[:text]}~"    
  #    end
  respond_to do |format|
    #        format.html { render :text => 'Returning text' }
    format.json { render json: @translation.to_json, callback: params[:callback]}
  end
end