Last active
November 8, 2019 07:05
-
-
Save chriskottom/46087a80089ff7b4796e72306dbc96e7 to your computer and use it in GitHub Desktop.
Estimates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Estimate < ApplicationRecord | |
def accept! | |
# update db | |
end | |
def reject! | |
# update db | |
end | |
... | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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