gefaalde orders
This commit is contained in:
parent
6b9e67ba2d
commit
df24bcd58e
5 changed files with 12 additions and 11 deletions
|
@ -1,5 +1,5 @@
|
|||
class OrdersController < ApplicationController
|
||||
before_action :logged_in_user, only: [:create, :destroy]
|
||||
before_action :logged_in_user, only: [ :destroy]
|
||||
|
||||
def new
|
||||
|
||||
|
@ -11,12 +11,12 @@ class OrdersController < ApplicationController
|
|||
|
||||
def show
|
||||
@user = User.find(params[:id])
|
||||
@order = selected_user.orders.build
|
||||
@order = @user.orders.build
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
@order = current_user.orders.build(order_params)
|
||||
user = User.find( 3) #MUST BE FIXED
|
||||
@order = user.orders.build(order_params)
|
||||
if @order.save
|
||||
#@flash[:success] = "Micropost created!"
|
||||
redirect_to root_url
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
module OrdersHelper
|
||||
|
||||
def select_user(user)
|
||||
selected_user = user.id
|
||||
end
|
||||
|
||||
def selected_user
|
||||
@selected_user ||= User.find_by(id: @user.id)
|
||||
return selected_user
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ module SessionsHelper
|
|||
@current_user ||= User.find_by(id: session[:user_id])
|
||||
end
|
||||
|
||||
def logged_in?
|
||||
def logged_in?
|
||||
!current_user.nil?
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class Order < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
|
||||
default_scope -> { order('created_at DESC') }
|
||||
validates :products, presence: true, length: { maximum: 140 }
|
||||
end
|
||||
|
|
|
@ -27,10 +27,6 @@ Rails.application.routes.draw do
|
|||
post 'order' => 'orders#create'
|
||||
delete 'chaos' => 'orders#destroy'
|
||||
|
||||
resources :orders, only: [:create, :destroy]
|
||||
|
||||
|
||||
|
||||
#account stuff
|
||||
get 'signup' => 'users#new'
|
||||
get 'login' => 'sessions#new'
|
||||
|
|
Loading…
Reference in a new issue