Need added (migrations+model+controller+templates+soft-deleting)
This commit is contained in:
parent
11d419aba1
commit
a867e95951
2
Gemfile
2
Gemfile
@ -66,3 +66,5 @@ gem 'wicked_pdf'
|
||||
gem 'wkhtmltopdf-binary'
|
||||
|
||||
gem "geocoder"
|
||||
|
||||
gem "paranoia", "~> 2.0"
|
||||
|
@ -128,6 +128,8 @@ GEM
|
||||
net-ssh (>= 2.6.5)
|
||||
nokogiri (1.6.6.2)
|
||||
mini_portile (~> 0.6.0)
|
||||
paranoia (2.1.4)
|
||||
activerecord (~> 4.0)
|
||||
rack (1.6.0)
|
||||
rack-test (0.6.3)
|
||||
rack (>= 1.0)
|
||||
@ -235,6 +237,7 @@ DEPENDENCIES
|
||||
kaminari-bootstrap
|
||||
mysql2
|
||||
net-ssh (~> 2.7.0)
|
||||
paranoia (~> 2.0)
|
||||
rails (= 4.2.0)
|
||||
rmagick
|
||||
rvm-capistrano (= 1.4.1)
|
||||
|
@ -5,7 +5,7 @@ class Public::MyAccountController < ApplicationController
|
||||
before_filter :auth_customer
|
||||
|
||||
def index
|
||||
|
||||
@needs = Kaminari.paginate_array(current_customer.needs).page(params[:page]).per(2)
|
||||
|
||||
end
|
||||
|
||||
|
48
app/controllers/public/needs_controller.rb
Normal file
48
app/controllers/public/needs_controller.rb
Normal file
@ -0,0 +1,48 @@
|
||||
class Public::NeedsController < ApplicationController
|
||||
|
||||
layout "public"
|
||||
|
||||
before_filter :auth_customer
|
||||
|
||||
def new
|
||||
@need = Need.new()
|
||||
end
|
||||
|
||||
def destroy
|
||||
@need = Need.find(params[:id])
|
||||
if(@need.destroy)
|
||||
flash[:notice] = "Besoin supprimé avec succès."
|
||||
end
|
||||
redirect_to public_my_account_path
|
||||
end
|
||||
|
||||
def edit
|
||||
@need = Need.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@need = Need.find(params[:id])
|
||||
if @need.update_attributes(need_params)
|
||||
flash[:notice] = "Besoin sauvegardé avec succès."
|
||||
redirect_to public_my_account_path
|
||||
else
|
||||
render :action => "edit"
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@need = Need.new(need_params)
|
||||
@need.author = current_customer
|
||||
if @need.save
|
||||
flash[:notice] = "Votre besoin à été créé avec succès."
|
||||
redirect_to public_my_account_path
|
||||
else
|
||||
render :action => "new"
|
||||
end
|
||||
end
|
||||
|
||||
def need_params
|
||||
params.require(:need).permit(:title, :description)
|
||||
end
|
||||
|
||||
end
|
@ -2,6 +2,8 @@ class Customer < ActiveRecord::Base
|
||||
|
||||
# Relationships
|
||||
|
||||
has_many :needs, foreign_key: 'author_id'
|
||||
|
||||
has_many :customer_favs
|
||||
has_many :annonce_favs, :through => :customer_favs, :class_name => "Annonce", :source => :annonce
|
||||
|
||||
@ -44,6 +46,7 @@ class Customer < ActiveRecord::Base
|
||||
|
||||
validates :need_1 , :presence => true, :if => :step3
|
||||
|
||||
|
||||
# Geocoder
|
||||
|
||||
reverse_geocoded_by :latitude, :longitude
|
||||
@ -213,6 +216,10 @@ class Customer < ActiveRecord::Base
|
||||
"#{address} #{address2} #{cp} #{city}"
|
||||
end
|
||||
|
||||
def fullname
|
||||
"#{firstname.capitalize} #{name.upcase}"
|
||||
end
|
||||
|
||||
def pseudo
|
||||
if self.pro
|
||||
self.organisation
|
||||
|
15
app/models/need.rb
Normal file
15
app/models/need.rb
Normal file
@ -0,0 +1,15 @@
|
||||
class Need < ActiveRecord::Base
|
||||
|
||||
max_paginates_per 10
|
||||
|
||||
|
||||
validates :title, :presence => true,
|
||||
:length => {:within => 4..128}
|
||||
|
||||
validates :description, :presence => true, length: {maximum: 65535}
|
||||
|
||||
belongs_to :author, class_name: 'Customer'
|
||||
|
||||
acts_as_paranoid
|
||||
|
||||
end
|
@ -12,11 +12,11 @@
|
||||
=link_to "renvoyer le mail de confirmation", public_reconfirm_email_path, :class => "btn btn-primary"
|
||||
|
||||
|
||||
.padding.center.white
|
||||
-if !current_customer.address or current_customer.need_1 == nil or !current_customer.account_validated
|
||||
|
||||
.padding.center.white
|
||||
%h2
|
||||
=current_customer.organisation
|
||||
-if !current_customer.address or current_customer.need_1 == nil
|
||||
|
||||
|
||||
-if !current_customer.address
|
||||
%p
|
||||
@ -24,9 +24,8 @@
|
||||
=render :partial => "public/my_account/step2"
|
||||
-elsif !current_customer.need_1
|
||||
%center
|
||||
|
||||
=render :partial => "public/my_account/step3"
|
||||
-else
|
||||
-elsif !current_customer.account_validated
|
||||
%p
|
||||
Merci ! Votre profil est complet, nous vous contacterons prochainement.
|
||||
%p
|
||||
@ -34,5 +33,28 @@
|
||||
|
||||
|
||||
|
||||
-if current_customer.account_validated
|
||||
.padding.center.white
|
||||
%h2
|
||||
=current_customer.organisation
|
||||
%p
|
||||
%i.fa.fa-user
|
||||
#{current_customer.fullname}
|
||||
%p
|
||||
%i.fa.fa-map-marker
|
||||
#{ current_customer.full_address}
|
||||
%p
|
||||
=link_to "Modifier mes infos", public_edit_infos_path, :class => "btn btn-primary"
|
||||
|
||||
|
||||
.padding.center.white
|
||||
%h3
|
||||
Mes besoins
|
||||
-if @needs.length > 0
|
||||
=render "public/needs/index", needs: @needs
|
||||
-else
|
||||
%p
|
||||
Vous n'avez pas encore créé de besoin
|
||||
=link_to "Déclarer un besoin", new_public_need_path, :class => "btn btn-primary"
|
||||
.padding.center.white
|
||||
%h3
|
||||
Ma liste de souhait
|
||||
|
6
app/views/public/needs/_form.html.haml
Normal file
6
app/views/public/needs/_form.html.haml
Normal file
@ -0,0 +1,6 @@
|
||||
= semantic_form_for [:public, @need] do |f|
|
||||
=f.inputs do
|
||||
= f.input :title, :label => "Titre de votre besoin"
|
||||
= f.input :description, :label => "Description", :rows => 5, :input_html => {:style => "height:100px;"}
|
||||
%br
|
||||
=f.submit "Sauvegarder", :class => "btn btn-primary"
|
18
app/views/public/needs/_index.html.haml
Normal file
18
app/views/public/needs/_index.html.haml
Normal file
@ -0,0 +1,18 @@
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
|
||||
%tr
|
||||
%th
|
||||
Titre du besoin
|
||||
%th
|
||||
État
|
||||
%th
|
||||
Souhaité par
|
||||
%th{:style => "width:100px"}
|
||||
|
||||
|
||||
%tbody
|
||||
|
||||
=render @needs
|
||||
|
||||
.pagination= paginate @needs
|
10
app/views/public/needs/_need.html.haml
Normal file
10
app/views/public/needs/_need.html.haml
Normal file
@ -0,0 +1,10 @@
|
||||
%tr{:id => need.id}
|
||||
%td
|
||||
=need.title
|
||||
%td
|
||||
|
||||
%td
|
||||
|
||||
%td.actions{:style => "width:150px;text-align:right"}
|
||||
= link_to i(:"trash-o btn btn-default"), [:public, need], :data => {:confirm => 'Voulez-vous vraiment supprimer ce besoin ?'}, method: :delete
|
||||
= link_to i(:"pencil btn btn-primary"), edit_public_need_path(need)
|
4
app/views/public/needs/edit.html.haml
Normal file
4
app/views/public/needs/edit.html.haml
Normal file
@ -0,0 +1,4 @@
|
||||
.center.padding.white
|
||||
%h2
|
||||
Modification d'un besoin existant
|
||||
=render :partial => "public/needs/form"
|
4
app/views/public/needs/new.html.haml
Normal file
4
app/views/public/needs/new.html.haml
Normal file
@ -0,0 +1,4 @@
|
||||
.center.padding.white
|
||||
%h2
|
||||
Déclaration d'un nouveau besoin
|
||||
=render :partial => "public/needs/form"
|
@ -20,6 +20,7 @@ Rails.application.routes.draw do
|
||||
get 'p/:mlm_token' => "public/customers#parrainage", :as => :mlm_token
|
||||
|
||||
namespace :public do
|
||||
|
||||
resources :customer_favs
|
||||
resources :customer_ribs do
|
||||
|
||||
@ -86,6 +87,9 @@ Rails.application.routes.draw do
|
||||
get 'my_account/edit_infos', :as => "edit_infos"
|
||||
get 'my_account/my_annonces', :as => "my_annonces"
|
||||
get 'my_account/reconfirm', :as => "reconfirm_email"
|
||||
|
||||
resources :needs
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
10
db/migrate/20151130121325_create_needs.rb
Normal file
10
db/migrate/20151130121325_create_needs.rb
Normal file
@ -0,0 +1,10 @@
|
||||
class CreateNeeds < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :needs do |t|
|
||||
t.string :title
|
||||
t.text :description
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddAuthorReferenceToNeed < ActiveRecord::Migration
|
||||
def change
|
||||
add_reference :needs, :author, index: true
|
||||
end
|
||||
end
|
6
db/migrate/20151130173626_add_delete_at_to_needs.rb
Normal file
6
db/migrate/20151130173626_add_delete_at_to_needs.rb
Normal file
@ -0,0 +1,6 @@
|
||||
class AddDeleteAtToNeeds < ActiveRecord::Migration
|
||||
def change
|
||||
add_column :needs, :deleted_at, :datetime
|
||||
add_index :needs, :deleted_at
|
||||
end
|
||||
end
|
14
db/schema.rb
14
db/schema.rb
@ -11,7 +11,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20151130111157) do
|
||||
ActiveRecord::Schema.define(version: 20151130173626) do
|
||||
|
||||
create_table "admins", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
@ -382,6 +382,18 @@ ActiveRecord::Schema.define(version: 20151130111157) do
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "needs", force: :cascade do |t|
|
||||
t.string "title", limit: 255
|
||||
t.text "description", limit: 65535
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "author_id", limit: 4
|
||||
t.datetime "deleted_at"
|
||||
end
|
||||
|
||||
add_index "needs", ["author_id"], name: "index_needs_on_author_id", using: :btree
|
||||
add_index "needs", ["deleted_at"], name: "index_needs_on_deleted_at", using: :btree
|
||||
|
||||
create_table "newsgroups", force: :cascade do |t|
|
||||
t.string "name", limit: 255
|
||||
t.string "slug", limit: 255
|
||||
|
9
test/fixtures/needs.yml
vendored
Normal file
9
test/fixtures/needs.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
title: MyString
|
||||
description: MyText
|
||||
|
||||
two:
|
||||
title: MyString
|
||||
description: MyText
|
7
test/models/need_test.rb
Normal file
7
test/models/need_test.rb
Normal file
@ -0,0 +1,7 @@
|
||||
require 'test_helper'
|
||||
|
||||
class NeedTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user