rails-app moved to examples folder
This commit is contained in:
@ -0,0 +1,2 @@
|
||||
class ApplicationController < ActionController::Base
|
||||
end
|
0
examples/rails-app/app/controllers/concerns/.keep
Normal file
0
examples/rails-app/app/controllers/concerns/.keep
Normal file
75
examples/rails-app/app/controllers/products_controller.rb
Normal file
75
examples/rails-app/app/controllers/products_controller.rb
Normal file
@ -0,0 +1,75 @@
|
||||
class ProductsController < ApplicationController
|
||||
before_action :authenticate_user!
|
||||
before_action :set_product, only: [:show, :edit, :update, :destroy]
|
||||
|
||||
# GET /products
|
||||
# GET /products.json
|
||||
def index
|
||||
@products = Product.all
|
||||
end
|
||||
|
||||
# GET /products/1
|
||||
# GET /products/1.json
|
||||
def show
|
||||
end
|
||||
|
||||
# GET /products/new
|
||||
def new
|
||||
@product = Product.new
|
||||
end
|
||||
|
||||
# GET /products/1/edit
|
||||
def edit
|
||||
end
|
||||
|
||||
# POST /products
|
||||
# POST /products.json
|
||||
def create
|
||||
@product = Product.new(product_params)
|
||||
|
||||
respond_to do |format|
|
||||
if @product.save
|
||||
format.html { redirect_to @product, notice: 'Product was successfully created.' }
|
||||
format.json { render :show, status: :created, location: @product }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /products/1
|
||||
# PATCH/PUT /products/1.json
|
||||
def update
|
||||
respond_to do |format|
|
||||
if @product.update(product_params)
|
||||
format.html { redirect_to @product, notice: 'Product was successfully updated.' }
|
||||
format.json { render :show, status: :ok, location: @product }
|
||||
else
|
||||
format.html { render :edit }
|
||||
format.json { render json: @product.errors, status: :unprocessable_entity }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /products/1
|
||||
# DELETE /products/1.json
|
||||
def destroy
|
||||
@product.destroy
|
||||
respond_to do |format|
|
||||
format.html { redirect_to products_url, notice: 'Product was successfully destroyed.' }
|
||||
format.json { head :no_content }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_product
|
||||
@product = Product.find(params[:id])
|
||||
end
|
||||
|
||||
# Never trust parameters from the scary internet, only allow the white list through.
|
||||
def product_params
|
||||
params.require(:product).permit(:name, :description, :price)
|
||||
end
|
||||
end
|
55
examples/rails-app/app/controllers/stripe_controller.rb
Normal file
55
examples/rails-app/app/controllers/stripe_controller.rb
Normal file
@ -0,0 +1,55 @@
|
||||
class StripeController < ApplicationController
|
||||
# GET /stripe/1
|
||||
# GET /stripe/1.json
|
||||
def show
|
||||
data = '{ "data": [
|
||||
{
|
||||
"id": 1,
|
||||
"customer_id": "$id",
|
||||
"object": "charge",
|
||||
"amount": 100,
|
||||
"amount_refunded": 0,
|
||||
"date": "01/01/2019",
|
||||
"application": null,
|
||||
"billing_details": {
|
||||
"address": "1 Infinity Drive",
|
||||
"zipcode": "94024"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"customer_id": "$id",
|
||||
"object": "charge",
|
||||
"amount": 150,
|
||||
"amount_refunded": 0,
|
||||
"date": "02/18/2019",
|
||||
"billing_details": {
|
||||
"address": "1 Infinity Drive",
|
||||
"zipcode": "94024"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"customer_id": "$id",
|
||||
"object": "charge",
|
||||
"amount": 150,
|
||||
"amount_refunded": 50,
|
||||
"date": "03/21/2019",
|
||||
"billing_details": {
|
||||
"address": "1 Infinity Drive",
|
||||
"zipcode": "94024"
|
||||
}
|
||||
}
|
||||
],
|
||||
"data_type": "charges",
|
||||
"total_count": 3,
|
||||
"next_cursor": null
|
||||
}'
|
||||
|
||||
data.gsub!("$id", params[:id])
|
||||
result = JSON.parse(data)
|
||||
|
||||
render json: result
|
||||
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user