Skip to content

Instantly share code, notes, and snippets.

@x1wins
x1wins / application_controller.rb
Last active December 12, 2019 14:53
model user_id onwer check
class ApplicationController < ActionController::Base
def is_owner user_id
unless user_id == current_user.id
render json: nil, status: :forbidden
return
end
end
def is_owner_object data
if data.nil? or data.user_id.nil?
return render status: :not_found
@x1wins
x1wins / ruby_utils.rb
Created September 18, 2023 17:00
ruby utils
# Rails: Is there a rails trick to adding commas to large numbers?
# https://stackoverflow.com/a/1078366/1399891
123456.to_fs(:delimited) # => "123,456"
@x1wins
x1wins / schema.rb
Created September 17, 2023 23:01
ahoy, pay gem - schema.rb
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#
@x1wins
x1wins / application_controller.rb
Last active September 19, 2023 05:02
Ahoy ApplicationController for REST API request, response log
class ApplicationController < ActionController::Base
after_action :track_action
protected
def track_action
ahoy.track "Called API", request.path_parameters.merge(log_request, log_response)
end
private
@x1wins
x1wins / conda.txt
Last active January 12, 2024 18:00
Installing Anaconda on macOS with brew
brew install --cask anaconda
/opt/homebrew/anaconda3/bin/conda init zsh
source ~/.zshrc
@x1wins
x1wins / schema.rb
Created September 17, 2023 23:03
spree solidus gem - schema.rb
# This file is auto-generated from the current state of the database. Instead
# of editing this file, please use the migrations feature of Active Record to
# incrementally modify your database, and then regenerate this schema definition.
#
# This file is the source Rails uses to define your schema when running `bin/rails
# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to
# be faster and is potentially less error prone than running all of your
# migrations from scratch. Old migrations may fail to apply correctly if those
# migrations use external dependencies or application code.
#