Skip to content

Instantly share code, notes, and snippets.

@chriskottom
Last active November 8, 2019 07:05
Show Gist options
  • Save chriskottom/46087a80089ff7b4796e72306dbc96e7 to your computer and use it in GitHub Desktop.
Save chriskottom/46087a80089ff7b4796e72306dbc96e7 to your computer and use it in GitHub Desktop.
Estimates
class Estimate < ApplicationRecord
def accept!
# update db
end
def reject!
# update db
end
...
end
# Estimates are documents that have a permalink that can be sent to a customer so they can approve or reject it.
# An instance of Estimate has two methods: "estimate.accept" or "estimate.reject" that just update a column in
# the database.
# Each action is implemented as a separate POST route, so a user can follow these links
# https://quadernoapp.com/estimate/secret_token/accept to accept
# https://quadernoapp.com/estimate/secret_token/reject to reject
class EstimatesController < ApplicationController
before_action :find_item
# Accepts the estimate
def accept
@estimate.accept!
redirect_to @estimate
end
# Rejects the estimate
def reject
@estimate.reject!
redirect_to @estimate
end
private
def find_item
@estimate = current_account.estimates.find(params[:secret_token])
end
end
Rails.application.routes.draw do
patch '/estimate/:secret_token/accept', to: 'estimates#accept'
put '/estimate/:secret_token/accept', to: 'estimates#accept'
patch '/estimate/:secret_token/reject', to: 'estimates#reject'
put '/estimate/:secret_token/reject', to: 'estimates#reject'
...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment