Skip to content

Commit

Permalink
added nickname in customer
Browse files Browse the repository at this point in the history
  • Loading branch information
farooqch11 committed May 3, 2018
1 parent 71d63c0 commit 27ede4e
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 28 deletions.
2 changes: 1 addition & 1 deletion app/controllers/backend/admin/customers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def new_resource
end

def customer_params
params.require(:customer).permit(:first_name, :last_name , :email ,:phone , :street , :city , :postcode , :gender)
params.require(:customer).permit(:first_name, :last_name , :email ,:phone , :street , :city , :postcode , :nickname)
end

end
8 changes: 3 additions & 5 deletions app/models/customer.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
class Customer < ApplicationRecord

enum gender: [:male , :female]

has_many :events

validates :first_name , :last_name , length: {minimum: 2, maximum: 50} , presence: true
validates :email , length: {minimum: 5, maximum: 100} , presence: true , uniqueness: true
validates_inclusion_of :gender, in: genders.keys
validates :first_name , :last_name , length: {minimum: 2, maximum: 50}, allow_blank: true
validates :nickname , length: {minimum: 2, maximum: 50} , presence: true
validates :email , length: {minimum: 5, maximum: 100}, allow_blank: true , uniqueness: true


def image
Expand Down
17 changes: 9 additions & 8 deletions app/views/backend/admin/customers/partials/_fields.html.haml
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
.row
.col-md-6
.col-md-12
.form-group.required
%label.control-label{:for => "full_name"} Nickname
=f.text_field :nickname , class: 'form-control' , placeholder: 'Enter nickname'
%span.help-block
.row
.col-md-6
.form-group
%label.control-label{:for => "full_name"} First name
=f.text_field :first_name , class: 'form-control' , placeholder: 'Enter first name'
%span.help-block
.col-md-6
.form-group.required
.form-group
%label.control-label{:for => "full_name"} Last name
=f.text_field :last_name , class: 'form-control' , placeholder: 'Enter last name'
%span.help-block
.row
.col-md-12
.col-md-6
.form-group.required
%label.control-label{:for => "full_name"} Email
=f.email_field :email , class: 'form-control' , placeholder: 'Enter email'
%span.help-block
.row
.col-md-6
.form-group
%label.control-label{:for => "full_name"} Gender
= f.select :gender, options_for_select(Customer.genders.collect { |s| [s[0].humanize, s[0]] }), {} , class: "form-control"
.col-md-6
.form-group
%label.control-label{:for => "full_name"} Telephone
Expand Down
6 changes: 6 additions & 0 deletions db/migrate/20180503175614_add_nickname_to_customer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddNicknameToCustomer < ActiveRecord::Migration[5.0]
def change
remove_column :customers , :gender , :integer
add_column :customers , :nickname , :string
end
end
47 changes: 33 additions & 14 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,44 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20171213202451) do
ActiveRecord::Schema.define(version: 20180503175614) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"

create_table "customers", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "email"
t.string "phone"
t.string "image"
t.integer "gender"
t.string "city"
t.string "street"
t.datetime "postcode"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "postcode"
t.string "nickname"
end

create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
t.integer "attempts", default: 0, null: false
t.text "handler", null: false
t.text "last_error"
t.datetime "run_at"
t.datetime "locked_at"
t.datetime "failed_at"
t.string "locked_by"
t.string "queue"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree
end

create_table "events", force: :cascade do |t|
t.string "title"
t.datetime "start"
t.datetime "end"
t.string "color"
t.integer "employee_id"
t.integer "customer_id"
Expand All @@ -45,8 +65,6 @@
t.string "zip"
t.string "address_line"
t.text "recurring"
t.datetime "end"
t.datetime "start"
t.integer "priority", default: 0
t.time "start_time"
t.time "end_time"
Expand All @@ -61,19 +79,19 @@
t.string "job_id"
t.float "job_duration", default: 1.0
t.integer "job_duration_type", default: 1
t.index ["customer_id"], name: "index_events_on_customer_id"
t.index ["employee_id"], name: "index_events_on_employee_id"
t.index ["customer_id"], name: "index_events_on_customer_id", using: :btree
t.index ["employee_id"], name: "index_events_on_employee_id", using: :btree
end

create_table "invoicing_ledger_items", force: :cascade do |t|
t.integer "sender_id"
t.integer "recipient_id"
t.string "type"
t.datetime "issue_date"
t.string "currency", limit: 3, null: false
t.string "currency", limit: 3, null: false
t.decimal "total_amount", precision: 20, scale: 4
t.decimal "tax_amount", precision: 20, scale: 4
t.string "status", limit: 20
t.integer "status", default: 0
t.string "identifier", limit: 50
t.string "description"
t.datetime "period_start"
Expand All @@ -86,6 +104,7 @@
create_table "invoicing_line_items", force: :cascade do |t|
t.integer "ledger_item_id"
t.integer "event_id"
t.string "type"
t.decimal "net_amount", precision: 20, scale: 4
t.decimal "tax_amount", precision: 20, scale: 4
t.datetime "tax_point"
Expand Down Expand Up @@ -151,11 +170,11 @@
t.float "hourly_rate"
t.string "picture"
t.string "color"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true
t.index ["invitations_count"], name: "index_users_on_invitations_count"
t.index ["invited_by_id"], name: "index_users_on_invited_by_id"
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree
t.index ["invitations_count"], name: "index_users_on_invitations_count", using: :btree
t.index ["invited_by_id"], name: "index_users_on_invited_by_id", using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end

end

0 comments on commit 27ede4e

Please sign in to comment.