From 95233449d4c6f87be3fb8c11288f4587888b3ce1 Mon Sep 17 00:00:00 2001 From: Jeff Casimir Date: Wed, 18 Dec 2013 12:01:24 -0700 Subject: [PATCH] Ideas --- app/controllers/orders_controller.rb | 7 ++++--- app/controllers/restaurants_controller.rb | 5 +++-- app/models/order.rb | 21 +++++++++++++++++++++ app/views/items/show.html.erb | 3 ++- app/views/orders/show.html.erb | 5 ++--- app/views/restaurants/_restaurant.html.erb | 6 ++++++ app/views/restaurants/index.html.erb | 18 ++---------------- config/initializers/user_notifier.rb | 5 +++++ 8 files changed, 45 insertions(+), 25 deletions(-) create mode 100644 app/views/restaurants/_restaurant.html.erb create mode 100644 config/initializers/user_notifier.rb diff --git a/app/controllers/orders_controller.rb b/app/controllers/orders_controller.rb index 0b9fd65..000ab9d 100644 --- a/app/controllers/orders_controller.rb +++ b/app/controllers/orders_controller.rb @@ -15,7 +15,9 @@ def new def show @order = current_order - @restaurants = @order.items.map(&:restaurant).uniq + #@restaurants = @order.items.map(&:restaurant).uniq + + @grouped_order_items = @order.order_items.group_by{|oi| oi.restaurant} end def checkout_one_restaurant @@ -50,9 +52,8 @@ def checkout end def place_order - current_order.update_status("completed") + current_order.place flash.notice = "Your order is successfull" - UserMailer.order_email(current_user, current_user.orders.last).deliver create_order redirect_to user_path(current_user) end diff --git a/app/controllers/restaurants_controller.rb b/app/controllers/restaurants_controller.rb index a4b4c05..8dd1ef2 100644 --- a/app/controllers/restaurants_controller.rb +++ b/app/controllers/restaurants_controller.rb @@ -8,7 +8,7 @@ def index end def new - @restaurant = Restaurant.new + @restaurant = current_user.restaurants.new @restaurant_detail = RestaurantDetail.new @hours = Hours.new end @@ -54,7 +54,8 @@ def edit def update if params[:restaurant][:status] @status = params[:restaurant][:status] - @restaurant = Restaurant.find(params[:id]) + #@restaurant = Restaurant.find(params[:id]) + @restaurant = current_user.restaurants.find(params[:id]) @restaurant.status = @status restaurant_admin = @restaurant.restaurant_employees.first @user = restaurant_admin.user diff --git a/app/models/order.rb b/app/models/order.rb index 164b6b9..9e0df4e 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -48,4 +48,25 @@ def generate_unique_url def order_username(customer_id) User.find(customer_id).username end + + def place + update_status("completed") + notifier.order_placed(customer, self) + end + + def notifier + USER_NOTIFIER.new + end +end + +class UserNotifierEmail + def order_placed(customer, self) + UserMailer.order_email(customer, self).deliver + end +end + +class UserNotifierFake + def order_placed(customer, self) + true + end end diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 5f8e939..6ce0956 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -11,9 +11,10 @@
  • <%= category.name %>
  • <% end %> +<% end %> <% if @order %> <%= button_to "Add to Order", add_item_path(@item.id), {class: "btn btn-success"} %> <% else %> <%= link_to "Add to Order", new_order_path(:item_id => @item.id), {:class => "btn btn-success"} %> <% end %> -<% end %> + diff --git a/app/views/orders/show.html.erb b/app/views/orders/show.html.erb index c011c5e..889399d 100644 --- a/app/views/orders/show.html.erb +++ b/app/views/orders/show.html.erb @@ -1,7 +1,7 @@

    Current Orders

    - <% @restaurants.each do |restaurant| %> + <% @grouped_order_item.each do |restaurant, order_items| %>

    <%= link_to restaurant.name, restaurant_path(restaurant)%> @@ -18,8 +18,7 @@ - <% @order_items = @order.find_order_items_by_restaurant_id(@order, restaurant.id) %> - <% @order_items.each do |order_item| %> + <% order_items.each do |order_item| %> <% item = order_item.item %> <%= link_to item.title, item_path(item.id) %> diff --git a/app/views/restaurants/_restaurant.html.erb b/app/views/restaurants/_restaurant.html.erb new file mode 100644 index 0000000..1a84101 --- /dev/null +++ b/app/views/restaurants/_restaurant.html.erb @@ -0,0 +1,6 @@ +

    + <%= link_to restaurant.name, restaurant_path(restaurant)%> +

    +<% if restaurant.restaurant_employees.any? %> +

    There is an employee

    +<% end %> diff --git a/app/views/restaurants/index.html.erb b/app/views/restaurants/index.html.erb index 53548e2..c0f4d78 100644 --- a/app/views/restaurants/index.html.erb +++ b/app/views/restaurants/index.html.erb @@ -1,23 +1,9 @@

    Active Restaurants

    - <% @restaurants.each do |restaurant| %> -

    - <%= link_to restaurant.name, restaurant_path(restaurant)%> -

    - <% if restaurant.restaurant_employees.any? %> -

    There is an employee

    - <% end %> - <% end %> + <%= render :partial => 'restaurant', :collection => @restaurants %>

    Pending Restaurants

    - <% @pending_restaurants.each do |restaurant| %> -

    - <%= link_to restaurant.name, restaurant_path(restaurant)%> -

    - <% if restaurant.restaurant_employees.any? %> -

    There is an employee

    - <% end %> - <% end %> + <%= render :partial => 'restaurant', :collection => @pending_restaurants %>

    diff --git a/config/initializers/user_notifier.rb b/config/initializers/user_notifier.rb new file mode 100644 index 0000000..31d7d6c --- /dev/null +++ b/config/initializers/user_notifier.rb @@ -0,0 +1,5 @@ +if Rails.env.development? || Rails.env.test? + USER_NOTIFIER = UserNotifierFake +else + USER_NOTIFIER = UserNotifierEmail +end