diff options
| author | mo <mo.khan@gmail.com> | 2017-08-30 22:42:47 -0600 |
|---|---|---|
| committer | mo <mo.khan@gmail.com> | 2017-08-30 22:42:47 -0600 |
| commit | aa90214867257516cca265d3e216790176526172 (patch) | |
| tree | 04acee662d5daa66aa98afcd6512382997aaf20b | |
| parent | 68479c0517d1fa99e68fa897d0e4009493b69b10 (diff) | |
add page of emails.
| -rw-r--r-- | app/controllers/emails_controller.rb | 5 | ||||
| -rw-r--r-- | app/views/emails/index.html.erb | 36 | ||||
| -rw-r--r-- | config/routes.rb | 1 | ||||
| -rw-r--r-- | db/migrate/20170831042718_add_unique_constraint_to_username.rb | 7 | ||||
| -rw-r--r-- | db/schema.rb | 5 |
5 files changed, 52 insertions, 2 deletions
diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb new file mode 100644 index 0000000..4804810 --- /dev/null +++ b/app/controllers/emails_controller.rb @@ -0,0 +1,5 @@ +class EmailsController < ApplicationController + def index + @emails = paginate(current_user.received_emails.order(created_at: :desc)) + end +end diff --git a/app/views/emails/index.html.erb b/app/views/emails/index.html.erb new file mode 100644 index 0000000..4d3d9af --- /dev/null +++ b/app/views/emails/index.html.erb @@ -0,0 +1,36 @@ +<div class="container"> + <div class="columns"> + <div class="column is-12"> + <table class="table is-bordered is-striped is-narrow"> + <thead> + <tr> + <th>to</th> + <th>from</th> + <th>subject</th> + <th>body</th> + <th>created at</th> + <th>updated at</th> + </tr> + </thead> + <tbody> + <% @emails.each do |email| %> + <tr> + <td><%= mail_to email.to[0]["email"] %></td> + <td><%= mail_to email.from["full"] %></td> + <td><%= email.subject %></td> + <td><%= email.body %></td> + <td><%= email.created_at %></td> + <td><%= email.updated_at %></td> + </tr> + <% end %> + </tbody> + </table> + </div> + </div> + + <div class="columns"> + <div class="column is-12"> + <%= paginate @emails, remote: false %> + </div> + </div> +</div> diff --git a/config/routes.rb b/config/routes.rb index ebe2d0f..0584b87 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -14,6 +14,7 @@ Rails.application.routes.draw do end end resources :profiles, only: [:index, :new, :create, :show, :edit, :update], constraints: { id: /[^\/]+/ } + resources :emails, only: [:index] resources :gyms, only: [:index, :show, :new, :create] resources :charts, only: [:index] resource :dashboards, only: [:show] diff --git a/db/migrate/20170831042718_add_unique_constraint_to_username.rb b/db/migrate/20170831042718_add_unique_constraint_to_username.rb new file mode 100644 index 0000000..38d2c7b --- /dev/null +++ b/db/migrate/20170831042718_add_unique_constraint_to_username.rb @@ -0,0 +1,7 @@ +class AddUniqueConstraintToUsername < ActiveRecord::Migration[5.0] + def change + remove_index :users, [:username] + add_index :users, [:username], unique: true + add_index :users, [:email], unique: true + end +end diff --git a/db/schema.rb b/db/schema.rb index 7600194..d1b4634 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: 20170824041919) do +ActiveRecord::Schema.define(version: 20170831042718) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -126,8 +126,9 @@ ActiveRecord::Schema.define(version: 20170824041919) do t.string "password_digest" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.index ["email"], name: "index_users_on_email", unique: true, using: :btree t.index ["username", "email"], name: "index_users_on_username_and_email", using: :btree - t.index ["username"], name: "index_users_on_username", using: :btree + t.index ["username"], name: "index_users_on_username", unique: true, using: :btree end create_table "workouts", id: :uuid, default: -> { "uuid_generate_v4()" }, force: :cascade do |t| |
