Sha256: 9834180a2dbc4649bc7c7d0a4e131a4b5b59154d29a60d02322ed31094776783

Contents?: true

Size: 1.49 KB

Versions: 2

Compression:

Stored size: 1.49 KB

Contents

class WhowishWordController < ActionController::Base
  
  def css
    
    text = ""
    
    Dir[File.expand_path("../../../public/stylesheets/*.css", __FILE__)].each { |f| 
      text += IO.read(f)
      text += "\n\n"
    }
    
    response.headers["Content-Type"] = "text/css; charset=utf-8"
    render :text=>text
    
  end
  
  def js
 
    text = ""
    
    all_files = Dir[File.expand_path("../../../public/javascripts/*.js", __FILE__)]
    all_files.sort! { |a, b| a <=> b}
    
    all_files.each { |file|
      text += IO.read(file)
      text += "\n\n"
    }
    
    response.headers["Content-Type"] = "text/javascript; charset=utf-8"
    render :text=>text
    
  end
  
  def change_word

    entity = WhowishWordHtml.first(:conditions=>{:word_id => params[:word_id].strip})

    entity = WhowishWordHtml.new if !entity

    entity.word_id = params[:word_id].strip
    entity.content = params[:content].strip
    
    if !entity.save
      
      error_message = "WhowishWord fails to change the word you specified.<br/>" + \
                      "Possible causes:<br/>" + \
                      "- Someone else changed the word at the very same time<br/>" + \
                      "- Database connection failed<br/>" + \
                      "By all means, please try again.<br/>"
                      
      render :json=>{:ok=>false,:error_message=>error_message}
      
    end
    
    WhowishWord.add_or_set_word(entity.word_id, entity.content)
    
    render :json=>{:ok=>true}
  end
  
  
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
whowish_word-0.3.3 lib/whowish_word/rails/app/controllers/whowish_word_controller.rb
whowish_word-0.3.2 lib/whowish_word/rails/app/controllers/whowish_word_controller.rb