Offer model & controller

This commit is contained in:
Nicolas VARROT 2015-12-09 22:14:15 +01:00
parent b3a37cd78f
commit 2e0c9a793f
7 changed files with 17 additions and 3 deletions

View File

@ -142,6 +142,15 @@ class Admin::NeedsController < ApplicationController
redirect_to admin_needs_path redirect_to admin_needs_path
end 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 private

View File

@ -1,14 +1,15 @@
class Admin::NeedsController < ApplicationController class Admin::OffersController < ApplicationController
layout "admin" layout "admin"
before_filter :auth_admin before_filter :auth_admin
before_action :build_category_tree, only:[:new, :update, :create, :edit, :index]
def index def index
end end
def new def new
@need = Need.find(params[:need_id])
@offer = Offer.new
end
def create def create

View File

@ -29,6 +29,7 @@ class Need < ActiveRecord::Base
has_many :wishes, dependent: :destroy has_many :wishes, dependent: :destroy
has_many :customers, -> { uniq }, through: :wishes has_many :customers, -> { uniq }, through: :wishes
has_many :messages, dependent: :destroy has_many :messages, dependent: :destroy
has_many :offers
belongs_to :category, class_name: "NeedCategory" belongs_to :category, class_name: "NeedCategory"
validates :title, :presence => true, length: {within: 4..128} validates :title, :presence => true, length: {within: 4..128}

View File

@ -1,2 +1,4 @@
class Offer < ActiveRecord::Base class Offer < ActiveRecord::Base
belongs_to :need
end end

View File

View File

View File

@ -244,6 +244,7 @@ Rails.application.routes.draw do
resources :needs do resources :needs do
resources :messages resources :messages
resources :wishes resources :wishes
resources :offers
member do member do
get :validate get :validate
get :refuse get :refuse