Created
November 5, 2015 20:43
-
-
Save gabeodess/797f9493d7e9a93ddd20 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 WholesaleOrdersController < ApplicationController | |
PERMITTED_PARAMS = [:address_id, :payment_method, :pickup, :shipping_method, :wholesale_order_items_attributes => [:ounces, :quantity, :great_coffee_id]] | |
before_filter :activated_check! | |
before_filter :load_wholesale_order, :only => [:show, :pay, :send_check] | |
before_filter :new_wholesale_order_from_params, :only => [:create, :shipping] | |
skip_before_filter :authenticate_user! | |
respond_to :json | |
layout "wholesale" | |
def send_check | |
@wholesale_order.update_attribute(:check_sent_at, Time.now) | |
respond_with @wholesale_order | |
end | |
def shipping | |
# TODO: This can be a very heavy request and should be moved into a background job to avoid weighing down web-dynos. | |
if @wholesale_order.valid_for_shipping_rates? | |
render :json => @wholesale_order.collapsed_shipping_rates | |
else | |
respond_with @wholesale_order | |
end | |
end | |
def pay | |
@wholesale_order.pay!(params[:wholesale_order][:card]) | |
errors = !@wholesale_order.errors.empty? | |
render :json => errors ? @wholesale_order.errors : @wholesale_order, :status => errors ? 422 : 200 | |
end | |
def index | |
@wholesale_orders = current_wholesaler.wholesale_orders.reorder("wholesale_orders.id DESC").page(params[:page]) | |
end | |
def create | |
@wholesale_order.save | |
respond_with @wholesale_order | |
end | |
private | |
def new_wholesale_order_from_params | |
@wholesale_order = current_wholesaler.wholesale_orders.build(:wholesaler => current_wholesaler) | |
@wholesale_order.assign_attributes(params.require(:wholesale_order).permit(*PERMITTED_PARAMS)) | |
end | |
def load_wholesale_order | |
@wholesale_order = Presenter::WholesaleOrder.new(current_wholesaler.wholesale_orders.find(params[:id]), view_context) | |
end | |
def activated_check! | |
render :inactive if current_wholesaler.activated_at.blank? | |
end | |
end |
This file contains hidden or 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
Started PATCH "/wholesale_orders/3/send_check.json" for 127.0.0.1 at 2015-11-05 15:39:15 -0500 | |
Wholesaler Load (0.5ms) SELECT "wholesalers".* FROM "wholesalers" WHERE "wholesalers"."id" = $1 ORDER BY "wholesalers"."id" ASC LIMIT 1 [["id", 4]] | |
Processing by WholesaleOrdersController#send_check as JSON | |
Parameters: {"id"=>"3"} | |
WholesaleOrder Load (0.3ms) SELECT "wholesale_orders".* FROM "wholesale_orders" WHERE "wholesale_orders"."wholesaler_id" = $1 AND "wholesale_orders"."id" = $2 LIMIT 1 [["wholesaler_id", 4], ["id", 3]] | |
(0.2ms) BEGIN | |
SQL (0.4ms) UPDATE "wholesale_orders" SET "charge" = $1, "updated_at" = $2 WHERE "wholesale_orders"."id" = $3 [["charge", "{\"check_sent_at\":\"2015-11-05T15:39:15.470-05:00\"}"], ["updated_at", "2015-11-05 20:39:15.474149"], ["id", 3]] | |
(7.2ms) COMMIT | |
WholesaleOrderItem Load (0.2ms) SELECT "wholesale_order_items".* FROM "wholesale_order_items" WHERE "wholesale_order_items"."wholesale_order_id" = $1 [["wholesale_order_id", 3]] | |
Payment Load (0.3ms) SELECT "payments".* FROM "payments" WHERE "payments"."wholesale_order_id" = $1 [["wholesale_order_id", 3]] | |
Rendered wholesale_orders/send_check.json.ruby (35.8ms) | |
Completed 200 OK in 70ms (Views: 44.9ms | ActiveRecord: 11.1ms) | |
TypeError (no implicit conversion of Array into String): | |
rack (1.6.4) lib/rack/etag.rb:67:in `<<' | |
rack (1.6.4) lib/rack/etag.rb:67:in `block in digest_body' | |
actionpack (4.2.4) lib/action_dispatch/http/response.rb:97:in `each' | |
actionpack (4.2.4) lib/action_dispatch/http/response.rb:97:in `each' | |
actionpack (4.2.4) lib/action_dispatch/http/response.rb:52:in `each' | |
actionpack (4.2.4) lib/action_dispatch/http/response.rb:361:in `each' | |
rack (1.6.4) lib/rack/etag.rb:65:in `digest_body' | |
rack (1.6.4) lib/rack/etag.rb:28:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/conditionalget.rb:38:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/head.rb:13:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/params_parser.rb:27:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/flash.rb:260:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/session/abstract/id.rb:225:in `context' | |
rack (1.6.4) lib/rack/session/abstract/id.rb:220:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/cookies.rb:560:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
activerecord (4.2.4) lib/active_record/query_cache.rb:36:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
activerecord (4.2.4) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
activerecord (4.2.4) lib/active_record/migration.rb:377:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call' | |
activesupport (4.2.4) lib/active_support/callbacks.rb:88:in `__run_callbacks__' | |
activesupport (4.2.4) lib/active_support/callbacks.rb:778:in `_run_call_callbacks' | |
activesupport (4.2.4) lib/active_support/callbacks.rb:81:in `run_callbacks' | |
actionpack (4.2.4) lib/action_dispatch/middleware/callbacks.rb:27:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/reloader.rb:73:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/remote_ip.rb:78:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app' | |
railties (4.2.4) lib/rails/rack/logger.rb:20:in `block in call' | |
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `block in tagged' | |
activesupport (4.2.4) lib/active_support/tagged_logging.rb:26:in `tagged' | |
activesupport (4.2.4) lib/active_support/tagged_logging.rb:68:in `tagged' | |
railties (4.2.4) lib/rails/rack/logger.rb:20:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/runtime.rb:18:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/lock.rb:17:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
font_assets (0.1.12) lib/font_assets/middleware.rb:29:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
rack (1.6.4) lib/rack/sendfile.rb:113:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
railties (4.2.4) lib/rails/engine.rb:518:in `call' | |
railties (4.2.4) lib/rails/application.rb:165:in `call' | |
newrelic_rpm (3.13.2.302) lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call' | |
puma (2.14.0) lib/puma/commonlogger.rb:31:in `call' | |
puma (2.14.0) lib/puma/configuration.rb:78:in `call' | |
puma (2.14.0) lib/puma/server.rb:541:in `handle_request' | |
puma (2.14.0) lib/puma/server.rb:388:in `process_client' | |
puma (2.14.0) lib/puma/server.rb:270:in `block in run' | |
puma (2.14.0) lib/puma/thread_pool.rb:106:in `call' | |
puma (2.14.0) lib/puma/thread_pool.rb:106:in `block in spawn_thread' | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_source.erb (4.9ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (4.1ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (2.2ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/actionpack-4.2.4/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (32.4ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/_markup.html.erb (1.2ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/_inner_console_markup.html.erb within layouts/inlined_string (1.1ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/_prompt_box_markup.html.erb within layouts/inlined_string (0.8ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/style.css.erb within layouts/inlined_string (0.8ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/console.js.erb within layouts/javascript (30.0ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/main.js.erb within layouts/javascript (0.7ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/error_page.js.erb within layouts/javascript (0.9ms) | |
Rendered /Users/gabeodess/.rvm/gems/ruby-2.1.6@ShareCoffee/gems/web-console-2.2.1/lib/web_console/templates/index.html.erb (65.2ms) |
This file contains hidden or 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
@wholesale_order.as_json |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment