Commit aa90214

mo <mo.khan@gmail.com>
2017-08-31 04:42:47
add page of emails.
1 parent 68479c0
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
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>
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]
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
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|