Merge branch 'guest_account'

This commit is contained in:
benji 2015-12-01 20:57:46 +01:00
commit 7f07d1a0ab
8 changed files with 32 additions and 3 deletions

BIN
app/assets/images/guest.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View file

@ -0,0 +1,9 @@
class Guest::OrdersController < OrdersController
before_action :load_guest
private
def load_guest
@user = User.guest
end
end

View file

@ -9,7 +9,7 @@ class OrdersController < ApplicationController
def create
if @order.save
flash[:success] = "#{@order.to_sentence} ordered. Enjoy it!"
flash[:success] = @order.flash_success
redirect_to root_path
else
@products = Product.all.for_sale.order(:name)

View file

@ -1,4 +1,6 @@
module ApplicationHelper
include ActionView::Helpers::NumberHelper
def bootstrap_class_for flash_type
{ success: "alert-success", error: "alert-danger", alert: "alert-warning", notice: "alert-info" }[flash_type] || flash_type.to_s
end

View file

@ -11,7 +11,7 @@
#
class Order < ActiveRecord::Base
include ActionView::Helpers::TextHelper
include ActionView::Helpers::TextHelper, ApplicationHelper
belongs_to :user, counter_cache: true
has_many :order_items, dependent: :destroy
@ -19,7 +19,7 @@ class Order < ActiveRecord::Base
before_validation :calculate_price
before_save { |o| o.order_items = o.order_items.reject{ |oi| oi.count == 0 } }
after_create :create_api_job
after_create :create_api_job, unless: -> { user.name == "Guest" }
validates :user, presence: true
validates_associated :order_items
@ -33,6 +33,12 @@ class Order < ActiveRecord::Base
}.to_sentence
end
def flash_success
f = "#{to_sentence} ordered."
f << " Please put #{euro_from_cents(price_cents)} in our pot!" if user.name == "Guest"
f << " Enjoy it!"
end
def deletable
self.created_at > Rails.application.config.call_api_after.ago
end

View file

@ -55,4 +55,10 @@ class User < ActiveRecord::Base
rescue
end
end
def self.guest
@guest || find_or_create_by(name: "Guest") do |user|
user.avatar = File.new(File.join("app", "assets", "images", "guest.png"))
end
end
end

View file

@ -7,5 +7,7 @@
- @last.each do |user|
= image_tag user.avatar(:small), class: "img-responsive img-circle img-thumbnail"
.col-md-11
.row.text-center
=link_to "Not a Zeus Account? Order as a guest.", new_guest_order_path, class: "btn btn-primary btn-lg"
.row
= render @users

View file

@ -36,4 +36,8 @@ Rails.application.routes.draw do
resources :barcodes, only: [:show, :index, :destroy]
get 'overview' => 'orders#overview', as: "orders"
namespace :guest do
resources :orders, only: [:new, :create]
end
end