diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 6622598..ec7840a 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -16,3 +16,11 @@ label.required:after { content: " *"; color: red; } + +.form-inline { + .form-group { + input { + width: 100%; + } + } +} diff --git a/app/controllers/flows/contacts_controller.rb b/app/controllers/flows/contacts_controller.rb new file mode 100644 index 0000000..0b47644 --- /dev/null +++ b/app/controllers/flows/contacts_controller.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true +class Flows::ContactsController < ApplicationController + def index + # sdcscsdcs + # @newsletters = current_user.newsletters.order(id: :asc) + end +end diff --git a/app/models/contact.rb b/app/models/contact.rb new file mode 100644 index 0000000..28a7b36 --- /dev/null +++ b/app/models/contact.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index b7b91bf..7cd0dba 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/flows/contacts/_contact.html.slim b/app/views/flows/contacts/_contact.html.slim new file mode 100644 index 0000000..6e408c5 --- /dev/null +++ b/app/views/flows/contacts/_contact.html.slim @@ -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) diff --git a/app/views/flows/contacts/index.html.slim b/app/views/flows/contacts/index.html.slim new file mode 100644 index 0000000..9ab821e --- /dev/null +++ b/app/views/flows/contacts/index.html.slim @@ -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' diff --git a/config/routes.rb b/config/routes.rb index f7b2523..18b883f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/db/migrate/20160918121902_create_users_contacts.rb b/db/migrate/20160918121902_create_users_contacts.rb new file mode 100644 index 0000000..c2bd5b8 --- /dev/null +++ b/db/migrate/20160918121902_create_users_contacts.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 1b28a3e..bcdf5d9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -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" @@ -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