diff --git a/app/controllers/admin/needs_controller.rb b/app/controllers/admin/needs_controller.rb index d2bd634..47d71d3 100644 --- a/app/controllers/admin/needs_controller.rb +++ b/app/controllers/admin/needs_controller.rb @@ -142,6 +142,15 @@ class Admin::NeedsController < ApplicationController redirect_to admin_needs_path end + def accept + @need = Need.find(params[:id]) + if @need.reject! + flash[:notice] = "Le besoin est maintenant négocié" + else + flash[:error] = "L'état actuel de ce besoin ne permet pas cette action" + end + redirect_to new_admin_need_offer_path(@need) + end private diff --git a/app/controllers/admin/offers_controller.rb b/app/controllers/admin/offers_controller.rb index 2345cf8..ac63498 100644 --- a/app/controllers/admin/offers_controller.rb +++ b/app/controllers/admin/offers_controller.rb @@ -1,14 +1,15 @@ -class Admin::NeedsController < ApplicationController +class Admin::OffersController < ApplicationController layout "admin" before_filter :auth_admin - before_action :build_category_tree, only:[:new, :update, :create, :edit, :index] def index end def new - + @need = Need.find(params[:need_id]) + @offer = Offer.new + end def create diff --git a/app/models/need.rb b/app/models/need.rb index 6bc8728..705c65a 100644 --- a/app/models/need.rb +++ b/app/models/need.rb @@ -29,6 +29,7 @@ class Need < ActiveRecord::Base has_many :wishes, dependent: :destroy has_many :customers, -> { uniq }, through: :wishes has_many :messages, dependent: :destroy + has_many :offers belongs_to :category, class_name: "NeedCategory" validates :title, :presence => true, length: {within: 4..128} diff --git a/app/models/offer.rb b/app/models/offer.rb index faa9a24..a676208 100644 --- a/app/models/offer.rb +++ b/app/models/offer.rb @@ -1,2 +1,4 @@ class Offer < ActiveRecord::Base + belongs_to :need + end diff --git a/app/views/admin/offers/index.html.haml b/app/views/admin/offers/index.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/app/views/admin/offers/new.html.haml b/app/views/admin/offers/new.html.haml new file mode 100644 index 0000000..e69de29 diff --git a/config/routes.rb b/config/routes.rb index 8774dd7..08c05b9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -244,6 +244,7 @@ Rails.application.routes.draw do resources :needs do resources :messages resources :wishes + resources :offers member do get :validate get :refuse