Skip to content

Commit

Permalink
Contacts page
Browse files Browse the repository at this point in the history
- association between users and contacts
  • Loading branch information
max-borisov authored and mpakus committed Sep 20, 2016
1 parent 25736b6 commit 8226af2
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ label.required:after {
content: " *";
color: red;
}

.form-inline {
.form-group {
input {
width: 100%;
}
}
}
7 changes: 7 additions & 0 deletions app/controllers/flows/contacts_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true
class Flows::ContactsController < ApplicationController
def index
# sdcscsdcs
# @newsletters = current_user.newsletters.order(id: :asc)
end
end
7 changes: 7 additions & 0 deletions app/models/contact.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Contact < ApplicationRecord
self.table_name = 'users'

has_and_belongs_to_many :users, join_table: :users_contacts

validates :name, :email, presence: true, length: { maximum: 255 }
end
1 change: 1 addition & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class User < ApplicationRecord
:trackable, :validatable

has_many :newsletters
has_and_belongs_to_many :contacts, join_table: :users_contacts

validates :name, presence: true, length: { maximum: 255 }
end
7 changes: 7 additions & 0 deletions app/views/flows/contacts/_contact.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- %w(Иван Федор Джордж Санта Камбэл Джинна Марина Инна).each do |name|
tr
td= rand(10)
td= link_to name, flow_path(id: :contact)
td= "#{name}@mail.ru"
td= rand(10)
td= rand(10)
20 changes: 20 additions & 0 deletions app/views/flows/contacts/index.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
h1 Мои Контакты

.panel.panel-success
.panel-body
form.form-inline
.form-group.col-lg-5
input placeholder="Имя" class="form-control"
.form-group.col-lg-5
input placeholder="E-mail" class="form-control"
.form-group.col-lg-2
button class="btn btn-success" Добавить

table.table.table-hover.table-striped
tr
th ID
th Имя
th E-mail
th Кол-во подписок
th Кол-во отписанных
= render 'contact'
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
devise_for :users
namespace :flows do
resources :newsletters, except: [:edit]
resources :contacts, only: [:index]
end
resources :flows, only: [:index, :show]
root to: 'flows#index'
Expand Down
8 changes: 8 additions & 0 deletions db/migrate/20160918121902_create_users_contacts.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class CreateUsersContacts < ActiveRecord::Migration[5.0]
def change
create_table :users_contacts, id: false do |t|
t.belongs_to :user, index: true
t.belongs_to :contact, index: true
end
end
end
9 changes: 8 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160917154254) do
ActiveRecord::Schema.define(version: 20160918121902) do

create_table "newsletters", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.string "name"
Expand Down Expand Up @@ -42,5 +42,12 @@
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end

create_table "users_contacts", id: false, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
t.integer "user_id"
t.integer "contact_id"
t.index ["contact_id"], name: "index_users_contacts_on_contact_id", using: :btree
t.index ["user_id"], name: "index_users_contacts_on_user_id", using: :btree
end

add_foreign_key "newsletters", "users"
end

0 comments on commit 8226af2

Please sign in to comment.