initial commit
This commit is contained in:
20
app/controllers/application_controller.rb
Normal file
20
app/controllers/application_controller.rb
Normal file
@@ -0,0 +1,20 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
# Prevent CSRF attacks by raising an exception.
|
||||
# For APIs, you may want to use :null_session instead.
|
||||
protect_from_forgery with: :exception
|
||||
|
||||
#before_filter :set_default_response_format
|
||||
#
|
||||
#private
|
||||
#def set_default_response_format
|
||||
# request.format = :json
|
||||
#end
|
||||
|
||||
before_filter :allow_cors
|
||||
def allow_cors
|
||||
headers['Access-Control-Allow-Origin'] = '*'
|
||||
headers['Access-Control-Allow-Methods'] = 'POST, PUT, DELETE, GET, OPTIONS'
|
||||
headers['Access-Control-Request-Method'] = '*'
|
||||
headers['Access-Control-Allow-Headers'] = 'Origin, X-Requested-With, Content-Type, Accept, Authorization'
|
||||
end
|
||||
end
|
||||
0
app/controllers/concerns/.keep
Normal file
0
app/controllers/concerns/.keep
Normal file
34
app/controllers/guesses_controller.rb
Normal file
34
app/controllers/guesses_controller.rb
Normal file
@@ -0,0 +1,34 @@
|
||||
class GuessesController < ApplicationController
|
||||
skip_before_filter :verify_authenticity_token
|
||||
#before_filter :allow_cors
|
||||
|
||||
|
||||
# GET /guesses
|
||||
# GET /guesses.json
|
||||
def index
|
||||
@guesses = Guess.all.order("created_at DESC")
|
||||
end
|
||||
|
||||
|
||||
# POST /guesses
|
||||
# POST /guesses.json
|
||||
def create
|
||||
@guess = Guess.new
|
||||
@guess.username = params[:username]
|
||||
@guess.definition = params[:definition]
|
||||
Rails.logger.debug(params.inspect)
|
||||
|
||||
respond_to do |format|
|
||||
if @guess.save
|
||||
format.json { render action: 'show', status: :created, location: @guess }
|
||||
else
|
||||
format.json { render json: @guess.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@guess = Guess.find(params[:id])
|
||||
end
|
||||
end
|
||||
|
||||
45
app/controllers/results_controller.rb
Normal file
45
app/controllers/results_controller.rb
Normal file
@@ -0,0 +1,45 @@
|
||||
class ResultsController < ApplicationController
|
||||
before_action :set_result, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /results
|
||||
# GET /results.json
|
||||
def index
|
||||
@results = Result.all
|
||||
end
|
||||
|
||||
# GET /results/1
|
||||
# GET /results/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
|
||||
|
||||
# POST /results
|
||||
# POST /results.json
|
||||
def create
|
||||
@result = Result.new(result_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @result.save
|
||||
format.html { redirect_to @result, notice: 'Result was successfully created.' }
|
||||
format.json { render action: 'show', status: :created, location: @result }
|
||||
else
|
||||
format.html { render action: 'new' }
|
||||
format.json { render json: @result.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_result
|
||||
@result = Result.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def result_params
|
||||
params.require(:result).permit(:user_id, :time)
|
||||
end
|
||||
end
|
||||
37
app/controllers/solutions_controller.rb
Normal file
37
app/controllers/solutions_controller.rb
Normal file
@@ -0,0 +1,37 @@
|
||||
class SolutionsController < ApplicationController
|
||||
|
||||
skip_before_filter :verify_authenticity_token
|
||||
|
||||
#before_filter :allow_cors
|
||||
|
||||
# GET /solutions
|
||||
# GET /solutions.json
|
||||
def index
|
||||
@solutions = Solution.all
|
||||
end
|
||||
|
||||
# GET /solutions/1
|
||||
# GET /solutions/1.json
|
||||
def show
|
||||
@solution = Solution.find(params[:id])
|
||||
end
|
||||
|
||||
|
||||
# POST /solutions
|
||||
# POST /solutions.json
|
||||
def create
|
||||
@solution = Solution.new
|
||||
@solution.time = params[:time]
|
||||
@solution.number = params[:number].to_i
|
||||
@solution.username = params[:username]
|
||||
|
||||
respond_to do |format|
|
||||
if @solution.save
|
||||
format.json { render action: 'show', status: :created, location: @solution }
|
||||
else
|
||||
format.json { render json: @solution.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
12
app/controllers/users_controller.rb
Normal file
12
app/controllers/users_controller.rb
Normal file
@@ -0,0 +1,12 @@
|
||||
class UsersController < ApplicationController
|
||||
|
||||
|
||||
# GET /users
|
||||
# GET /users.json
|
||||
def index
|
||||
username = params[:username]
|
||||
@solutions = Solution.all.where(:username => username).order("created_at DESC")
|
||||
@guesses = Guess.all.where(:username => username).order("created_at DESC")
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user