Skip to content
This repository has been archived by the owner on Mar 8, 2021. It is now read-only.

Commit

Permalink
Fix wrong reference columns
Browse files Browse the repository at this point in the history
  • Loading branch information
miyukki committed Sep 5, 2015
1 parent 6bb8c62 commit 0e43dd1
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion app/controllers/session_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def slack_callback
# >> auth.info.user_id
# => "U03AE1H0U"

credential = SlackCredential.find_or_initialize_by(user_id: auth.info.user_id)
credential = SlackCredential.find_or_initialize_by(slack_user_id: auth.info.user_id)
user = if credential.new_record?
User.create(email: auth.info.email,
name: auth.info.name,
Expand Down
2 changes: 2 additions & 0 deletions app/models/slack_credential.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class SlackCredential < ActiveRecord::Base
belongs_to :user

validates :slack_user_id, uniqueness: true
end
1 change: 1 addition & 0 deletions app/views/pages/_page.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@

.content
= raw page.render_content

= render 'likes/list', page: page
= render 'comments/list', page: page
3 changes: 0 additions & 3 deletions app/views/pages/show.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
- content_for :css do
- stylesheet_link_tag 'pages'

- if @page
= render 'page', page: @page
- else
Expand Down
12 changes: 12 additions & 0 deletions db/migrate/20150905135019_fix_wrong_reference_columns.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class FixWrongReferenceColumns < ActiveRecord::Migration
def change
remove_index :slack_credentials, name: :index_slack_credentials_on_users_id
rename_column :slack_credentials, :user_id, :slack_user_id
rename_column :slack_credentials, :users_id, :user_id
add_index :slack_credentials, [:user_id], name: :index_slack_credentials_on_user_id

remove_index :pages, name: :index_pages_on_users_id
rename_column :pages, :users_id, :user_id
add_index :pages, [:user_id], name: :index_pages_on_user_id
end
end
16 changes: 8 additions & 8 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20150905024738) do
ActiveRecord::Schema.define(version: 20150905135019) do

create_table "comments", force: :cascade do |t|
t.integer "user_id"
Expand Down Expand Up @@ -51,13 +51,13 @@
t.string "path"
t.text "title"
t.text "content"
t.integer "users_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "pages", ["content"], name: "index_pages_on_content"
add_index "pages", ["users_id"], name: "index_pages_on_users_id"
add_index "pages", ["user_id"], name: "index_pages_on_user_id"

create_table "renamed_pages", force: :cascade do |t|
t.string "before_path"
Expand All @@ -67,13 +67,13 @@
end

create_table "slack_credentials", force: :cascade do |t|
t.integer "users_id"
t.string "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "slack_user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

add_index "slack_credentials", ["users_id"], name: "index_slack_credentials_on_users_id"
add_index "slack_credentials", ["user_id"], name: "index_slack_credentials_on_user_id"

create_table "users", force: :cascade do |t|
t.string "name"
Expand Down

0 comments on commit 0e43dd1

Please sign in to comment.