I have been running a few migrations and it doesnt update the schema file. I know the migrations have correctly changed my database but it seems my schema file wont change anymore... Here's my schema file. It misses the last table I have created (table 'notifications') and the several migrations I runned on this table.
ActiveRecord::Schema.define(version: 20150501141614) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
t.text "body"
t.string "resource_id", null: false
t.string "resource_type", null: false
t.integer "author_id"
t.string "author_type"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "active_admin_comments", ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree
add_index "active_admin_comments", ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree
add_index "active_admin_comments", ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
create_table "activities", force: :cascade do |t|
t.integer "trackable_id"
t.string "trackable_type"
t.integer "owner_id"
t.string "owner_type"
t.string "key"
t.text "parameters"
t.integer "recipient_id"
t.string "recipient_type"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "activities", ["owner_id", "owner_type"], name: "index_activities_on_owner_id_and_owner_type", using: :btree
add_index "activities", ["recipient_id", "recipient_type"], name: "index_activities_on_recipient_id_and_recipient_type", using: :btree
add_index "activities", ["trackable_id", "trackable_type"], name: "index_activities_on_trackable_id_and_trackable_type", using: :btree
create_table "clients", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "convocations", force: :cascade do |t|
t.date "date"
t.time "hour"
t.integer "subscription_id"
t.string "status", default: "pending"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "convocations", ["subscription_id"], name: "index_convocations_on_subscription_id", using: :btree
create_table "mailboxer_conversation_opt_outs", force: :cascade do |t|
t.integer "unsubscriber_id"
t.string "unsubscriber_type"
t.integer "conversation_id"
end
add_index "mailboxer_conversation_opt_outs", ["conversation_id"], name: "index_mailboxer_conversation_opt_outs_on_conversation_id", using: :btree
add_index "mailboxer_conversation_opt_outs", ["unsubscriber_id", "unsubscriber_type"], name: "index_mailboxer_conversation_opt_outs_on_unsubscriber_id_type", using: :btree
create_table "mailboxer_conversations", force: :cascade do |t|
t.string "subject", default: ""
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "mailboxer_notifications", force: :cascade do |t|
t.string "type"
t.text "body"
t.string "subject", default: ""
t.integer "sender_id"
t.string "sender_type"
t.integer "conversation_id"
t.boolean "draft", default: false
t.string "notification_code"
t.integer "notified_object_id"
t.string "notified_object_type"
t.string "attachment"
t.datetime "updated_at", null: false
t.datetime "created_at", null: false
t.boolean "global", default: false
t.datetime "expires"
end
add_index "mailboxer_notifications", ["conversation_id"], name: "index_mailboxer_notifications_on_conversation_id", using: :btree
add_index "mailboxer_notifications", ["notified_object_id", "notified_object_type"], name: "index_mailboxer_notifications_on_notified_object_id_and_type", using: :btree
add_index "mailboxer_notifications", ["sender_id", "sender_type"], name: "index_mailboxer_notifications_on_sender_id_and_sender_type", using: :btree
add_index "mailboxer_notifications", ["type"], name: "index_mailboxer_notifications_on_type", using: :btree
create_table "mailboxer_receipts", force: :cascade do |t|
t.integer "receiver_id"
t.string "receiver_type"
t.integer "notification_id", null: false
t.boolean "is_read", default: false
t.boolean "trashed", default: false
t.boolean "deleted", default: false
t.string "mailbox_type", limit: 25
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "mailboxer_receipts", ["notification_id"], name: "index_mailboxer_receipts_on_notification_id", using: :btree
add_index "mailboxer_receipts", ["receiver_id", "receiver_type"], name: "index_mailboxer_receipts_on_receiver_id_and_receiver_type", using: :btree
create_table "messages", force: :cascade do |t|
t.integer "user_id"
t.datetime "read_at"
t.text "content"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "convocation_id"
end
add_index "messages", ["user_id"], name: "index_messages_on_user_id", using: :btree
create_table "subscriptions", force: :cascade do |t|
t.integer "user_id"
t.integer "tournament_id"
t.string "status", default: "pending"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "subscriptions", ["tournament_id"], name: "index_subscriptions_on_tournament_id", using: :btree
add_index "subscriptions", ["user_id"], name: "index_subscriptions_on_user_id", using: :btree
create_table "tournaments", force: :cascade do |t|
t.integer "user_id"
t.string "genre"
t.string "category"
t.boolean "accepted"
t.integer "amount"
t.date "starts_on"
t.date "ends_on"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "address"
t.string "city"
t.string "name"
t.string "club_organisateur"
t.float "latitude"
t.float "longitude"
end
add_index "tournaments", ["user_id"], name: "index_tournaments_on_user_id", using: :btree
create_table "transfers", force: :cascade do |t|
t.string "status"
t.integer "mangopay_transaction_id"
t.string "category"
t.json "archive"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "tournament_id"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: ""
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
t.string "last_name"
t.string "ranking"
t.boolean "judge", default: false
t.string "genre"
t.string "date_of_birth"
t.string "licence_number"
t.integer "judge_number"
t.string "invitation_token"
t.datetime "invitation_created_at"
t.datetime "invitation_sent_at"
t.datetime "invitation_accepted_at"
t.integer "invitation_limit"
t.integer "invited_by_id"
t.string "invited_by_type"
t.integer "invitations_count", default: 0
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
t.string "name"
t.string "telephone"
t.string "picture_file_name"
t.string "picture_content_type"
t.integer "picture_file_size"
t.datetime "picture_updated_at"
t.string "provider"
t.string "uid"
t.string "picture"
t.string "token"
t.datetime "token_expiry"
t.boolean "admin", default: false, null: false
t.string "licencepicture_file_name"
t.string "licencepicture_content_type"
t.integer "licencepicture_file_size"
t.datetime "licencepicture_updated_at"
t.string "certifmedpicture_file_name"
t.string "certifmedpicture_content_type"
t.integer "certifmedpicture_file_size"
t.datetime "certifmedpicture_updated_at"
t.string "attestationformationja_file_name"
t.string "attestationformationja_content_type"
t.integer "attestationformationja_file_size"
t.datetime "attestationformationja_updated_at"
t.integer "client_id"
t.integer "mangopay_natural_user_id"
t.integer "wallet_id"
t.integer "kyc_document_id"
t.integer "card_id"
t.datetime "birthdate"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true, using: :btree
add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", unique: true, using: :btree
add_index "users", ["invitations_count"], name: "index_users_on_invitations_count", using: :btree
add_index "users", ["invited_by_id"], name: "index_users_on_invited_by_id", using: :btree
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
add_foreign_key "convocations", "subscriptions"
add_foreign_key "mailboxer_conversation_opt_outs", "mailboxer_conversations", column: "conversation_id", name: "mb_opt_outs_on_conversations_id"
add_foreign_key "mailboxer_notifications", "mailboxer_conversations", column: "conversation_id", name: "notifications_on_conversation_id"
add_foreign_key "mailboxer_receipts", "mailboxer_notifications", column: "notification_id", name: "receipts_on_notification_id"
add_foreign_key "subscriptions", "tournaments"
add_foreign_key "subscriptions", "users"
add_foreign_key "tournaments", "users"
end
I then ran rake db:drop db:create db:migrate but my schema file was still incomplete. I then tried to run another migration just to check:
class AddColumnClubToUsers < ActiveRecord::Migration
def change
add_column :users, :club, :string
end
end
but the schema file still wouldnt update
Just rebuild DB in development use: rake db:drop db:create db:migrate. This command should drop DB and rebuild it from scratch include schema.rb.
If this is doesn't work then change your new migrations. Probably you have mistake (i.e. typo in method name, etc.).
Related
Users can upload tracks and create playlist. I have a model for playlist and i have a model for playlist_track which is for users that can save to the playlist. I can create a new playlist but how do i add the tracks to the playlist in the views?
ActiveRecord::Schema.define(version: 2018_12_06_050857) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
t.string "record_type", null: false
t.bigint "record_id", null: false
t.bigint "blob_id", null: false
t.datetime "created_at", null: false
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
t.index ["record_type", "record_id", "name", "blob_id"], name: "index_active_storage_attachments_uniqueness", unique: true
end
create_table "active_storage_blobs", force: :cascade do |t|
t.string "key", null: false
t.string "filename", null: false
t.string "content_type"
t.text "metadata"
t.bigint "byte_size", null: false
t.string "checksum", null: false
t.datetime "created_at", null: false
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
end
create_table "playlist_tracks", force: :cascade do |t|
t.integer "playlist_id"
t.integer "track_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "playlists", force: :cascade do |t|
t.string "title"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "plays", force: :cascade do |t|
t.integer "user_id"
t.integer "track_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "tracks", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "genre"
t.integer "user_id"
t.string "name"
t.date "release_date"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "username"
t.index ["email"], name: "index_users_on_email", unique: true
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
end
Here is my track model
class Track < ApplicationRecord
has_many_attached :mp3
belongs_to :user, optional: true
has_many :playlist_tracks
has_many :playlists, through: :playlist_tracks
has_many :plays
end
and here is my playist_track model
class PlaylistTrack < ApplicationRecord
belongs_to :playlist
belongs_to :track
end
I am trying to deploy a big change I made to my code into heroku.
When I run heroku run rails db:migrate I get the following error:
I, [2018-05-01T18:07:40.587276 #4] INFO -- : Migrating to AddShopToListing (20180415173504)
D, [2018-05-01T18:07:40.592452 #4] DEBUG -- : (1.1ms) BEGIN
== 20180415173504 AddShopToListing: migrating =================================
-- add_reference(:listings, :shop, {:references=>:shops, :index=>true})
D, [2018-05-01T18:07:40.597146 #4] DEBUG -- : (2.7ms) ALTER TABLE "listings" ADD "shop_id" bigint
D, [2018-05-01T18:07:40.690959 #4] DEBUG -- : (87.4ms) CREATE INDEX "index_listings_on_shop_id" ON "listings" ("shop_id")
-> 0.0983s
-- add_foreign_key(:listings, :shop, {:column=>:shop_id})
D, [2018-05-01T18:07:40.699348 #4] DEBUG -- : (6.9ms) ALTER TABLE "listings" ADD CONSTRAINT "fk_rails_72ed4e1344"
FOREIGN KEY ("shop_id")
REFERENCES "shop" ("id")
D, [2018-05-01T18:07:40.704937 #4] DEBUG -- : (5.3ms) ROLLBACK
D, [2018-05-01T18:07:40.709352 #4] DEBUG -- : (4.1ms) SELECT pg_advisory_unlock(391033951906602690)
rails aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "shop" does not exist
: ALTER TABLE "listings" ADD CONSTRAINT "fk_rails_72ed4e1344"
FOREIGN KEY ("shop_id")
REFERENCES "shop" ("id")
Here is the offending migration file:
class AddShopToListing < ActiveRecord::Migration[5.1]
def change
add_reference :listings, :shop, references: :shops, index: true
add_foreign_key :listings, :shop, column: :shop_id
end
end
I cannot find what is causing this problem - the only thing I see is that in my heroku schema I have these lines:
add_foreign_key "sellers", "users"
add_foreign_key "shops", "listings"
add_foreign_key "shops", "sellers"
add_foreign_key "shops", "users"
When on my local schema I do not.
Here's the local schema:
ActiveRecord::Schema.define(version: 20180501104731) do
create_table "letsencrypt_plugin_challenges", force: :cascade do |t|
t.text "response"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "letsencrypt_plugin_settings", force: :cascade do |t|
t.text "private_key"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "listings", force: :cascade do |t|
t.integer "listing_id"
t.string "state"
t.integer "user_id"
t.integer "category_id"
t.string "title"
t.float "original_creation_tsz"
t.float "ending_tsz"
t.float "last_modified_tsz"
t.float "creation_tsz"
t.string "price"
t.string "currency_code"
t.integer "quantity"
t.string "tag_1"
t.string "tag_2"
t.string "tag_3"
t.string "tag_4"
t.string "tag_5"
t.string "tag_6"
t.string "tag_7"
t.string "tag_8"
t.string "tag_9"
t.string "tag_10"
t.string "tag_11"
t.string "tag_12"
t.string "tag_13"
t.integer "category_path_ids"
t.float "state_tsz"
t.string "url"
t.integer "views"
t.integer "num_favorers"
t.boolean "is_supply"
t.boolean "is_private"
t.string "recipient"
t.string "occasion"
t.boolean "is_digital"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "tags", default: "--- []\n"
t.string "img"
t.integer "shop_id"
t.index ["listing_id"], name: "index_listings_on_listing_id", unique: true
t.index ["shop_id"], name: "index_listings_on_shop_id"
t.index ["tag_1"], name: "index_listings_on_tag_1"
t.index ["tag_10"], name: "index_listings_on_tag_10"
t.index ["tag_11"], name: "index_listings_on_tag_11"
t.index ["tag_12"], name: "index_listings_on_tag_12"
t.index ["tag_13"], name: "index_listings_on_tag_13"
t.index ["tag_2"], name: "index_listings_on_tag_2"
t.index ["tag_3"], name: "index_listings_on_tag_3"
t.index ["tag_4"], name: "index_listings_on_tag_4"
t.index ["tag_5"], name: "index_listings_on_tag_5"
t.index ["tag_6"], name: "index_listings_on_tag_6"
t.index ["tag_7"], name: "index_listings_on_tag_7"
t.index ["tag_8"], name: "index_listings_on_tag_8"
t.index ["tag_9"], name: "index_listings_on_tag_9"
end
create_table "searches", force: :cascade do |t|
t.string "term"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "searches_listings", force: :cascade do |t|
t.integer "search_id"
t.integer "listing_id"
t.index ["listing_id"], name: "index_searches_listings_on_listing_id"
t.index ["search_id"], name: "index_searches_listings_on_search_id"
end
create_table "sellers", force: :cascade do |t|
t.string "name"
t.integer "seller_id"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_sellers_on_user_id"
end
create_table "shops", force: :cascade do |t|
t.integer "shop_id"
t.string "shop_name"
t.integer "user_id"
t.float "creation_tsz"
t.string "title"
t.string "announcement"
t.boolean "is_vacation"
t.float "last_updated_tsz"
t.integer "listing_active_count"
t.integer "digital_listing_count"
t.string "login_name"
t.string "url"
t.string "image_url_760x100"
t.integer "num_favorers"
t.string "icon_url_fullxfull"
t.boolean "is_using_structured_policies"
t.integer "listing_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "seller_id"
t.index ["listing_id"], name: "index_shops_on_listing_id"
t.index ["seller_id"], name: "index_shops_on_seller_id"
t.index ["user_id"], name: "index_shops_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.string "remember_digest"
t.boolean "admin", default: false
t.string "activation_digest"
t.boolean "activated", default: false
t.datetime "activated_at"
t.string "reset_digest"
t.datetime "reset_sent_at"
t.string "request_token"
t.string "request_secret"
t.string "oauth_verifier"
t.string "oauth_token"
t.string "login_name"
t.integer "user_id"
t.boolean "accept_terms"
t.boolean "accept_privacy"
t.index ["email"], name: "index_users_on_email", unique: true
end
end
Here is the heroku schema:
enable_extension "plpgsql"
create_table "letsencrypt_plugin_challenges", id: :serial, force: :cascade do |t|
t.text "response"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "letsencrypt_plugin_settings", id: :serial, force: :cascade do |t|
t.text "private_key"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "listings", force: :cascade do |t|
t.integer "listing_id"
t.string "state"
t.integer "user_id"
t.integer "category_id"
t.string "title"
t.float "original_creation_tsz"
t.float "ending_tsz"
t.float "last_modified_tsz"
t.float "creation_tsz"
t.string "price"
t.string "currency_code"
t.integer "quantity"
t.string "tag_1"
t.string "tag_2"
t.string "tag_3"
t.string "tag_4"
t.string "tag_5"
t.string "tag_6"
t.string "tag_7"
t.string "tag_8"
t.string "tag_9"
t.string "tag_10"
t.string "tag_11"
t.string "tag_12"
t.string "tag_13"
t.integer "category_path_ids"
t.float "state_tsz"
t.string "url"
t.integer "views"
t.integer "num_favorers"
t.boolean "is_supply"
t.boolean "is_private"
t.string "recipient"
t.string "occasion"
t.boolean "is_digital"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.text "tags", default: "--- []\n"
t.string "img"
t.index ["listing_id"], name: "index_listings_on_listing_id", unique: true
t.index ["tag_1"], name: "index_listings_on_tag_1"
t.index ["tag_10"], name: "index_listings_on_tag_10"
t.index ["tag_11"], name: "index_listings_on_tag_11"
t.index ["tag_12"], name: "index_listings_on_tag_12"
t.index ["tag_13"], name: "index_listings_on_tag_13"
t.index ["tag_2"], name: "index_listings_on_tag_2"
t.index ["tag_3"], name: "index_listings_on_tag_3"
t.index ["tag_4"], name: "index_listings_on_tag_4"
t.index ["tag_5"], name: "index_listings_on_tag_5"
t.index ["tag_6"], name: "index_listings_on_tag_6"
t.index ["tag_7"], name: "index_listings_on_tag_7"
t.index ["tag_8"], name: "index_listings_on_tag_8"
t.index ["tag_9"], name: "index_listings_on_tag_9"
end
create_table "sellers", force: :cascade do |t|
t.string "name"
t.integer "seller_id"
t.bigint "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["user_id"], name: "index_sellers_on_user_id"
end
create_table "shops", force: :cascade do |t|
t.integer "shop_id"
t.string "shop_name"
t.bigint "user_id"
t.float "creation_tsz"
t.string "title"
t.string "announcement"
t.boolean "is_vacation"
t.float "last_updated_tsz"
t.integer "listing_active_count"
t.integer "digital_listing_count"
t.string "login_name"
t.string "url"
t.string "image_url_760x100"
t.integer "num_favorers"
t.string "icon_url_fullxfull"
t.boolean "is_using_structured_policies"
t.bigint "listing_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.bigint "seller_id"
t.index ["listing_id"], name: "index_shops_on_listing_id"
t.index ["seller_id"], name: "index_shops_on_seller_id"
t.index ["user_id"], name: "index_shops_on_user_id"
end
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.string "remember_digest"
t.boolean "admin", default: false
t.string "activation_digest"
t.boolean "activated", default: false
t.datetime "activated_at"
t.string "reset_digest"
t.datetime "reset_sent_at"
t.string "request_token"
t.string "request_secret"
t.string "oauth_verifier"
t.string "oauth_token"
t.string "login_name"
t.integer "user_id"
t.index ["email"], name: "index_users_on_email", unique: true
end
add_foreign_key "sellers", "users"
add_foreign_key "shops", "listings"
add_foreign_key "shops", "sellers"
add_foreign_key "shops", "users"
end
Could you please help me?
I tried everything, including rolling back in the app to the day before I created the Shop model, but apparently it doesn't roll the db.
I also tried cloning it locally to work on the code from there but it clones the most recent commit, not the one that is currently active in the app.
Thanks in advance!
The issue happens here:
-- add_foreign_key(:listings, :shop, {:column=>:shop_id})
ALTER TABLE "listings"
ADD CONSTRAINT "fk_rails_72ed4e1344"
FOREIGN KEY ("shop_id")
REFERENCES "shop" ("id") -- <<<< HERE, it should be `shops` instead of `shop`
The second argument of add_foreign_key is supposed to be the table's name, in your case:
add_foreign_key :listings, :shops, column: :shop_id
# ^ plural
I have a model called room and in the show view I want to display other rooms nearby.
show.html.erb
<div>
<% for room in #room.nearbys(10) %>
<%= image_tag room.photos[0].image.url(:medium) %>
<%= link_to room.listing_name, room %><br>
(<%= room.distance.round(2) %> miles away)
<% end %>
</div>
schema.rb
ActiveRecord::Schema.define(version: 20161006135631) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
create_table "active_admin_comments", force: :cascade do |t|
t.string "namespace"
t.text "body"
t.string "resource_id", null: false
t.string "resource_type", null: false
t.string "author_type"
t.integer "author_id"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["author_type", "author_id"], name: "index_active_admin_comments_on_author_type_and_author_id", using: :btree
t.index ["namespace"], name: "index_active_admin_comments_on_namespace", using: :btree
t.index ["resource_type", "resource_id"], name: "index_active_admin_comments_on_resource_type_and_resource_id", using: :btree
end
create_table "admin_users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["email"], name: "index_admin_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_admin_users_on_reset_password_token", unique: true, using: :btree
end
create_table "photos", force: :cascade do |t|
t.integer "room_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.index ["room_id"], name: "index_photos_on_room_id", using: :btree
end
create_table "rooms", force: :cascade do |t|
t.string "listing_name"
t.string "accommodation_type"
t.integer "persons"
t.integer "property"
t.integer "living_area"
t.text "rooms_total"
t.text "features_short"
t.string "pets"
t.string "smoking"
t.string "check_in"
t.string "check_out"
t.string "location"
t.text "distance"
t.text "features_long"
t.text "detailed_description"
t.text "house_rules"
t.string "address"
t.text "video"
t.integer "nightly_price"
t.integer "hourly_price"
t.text "detailed_price"
t.boolean "active"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "latitude"
t.float "longitude"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.inet "current_sign_in_ip"
t.inet "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "firstname"
t.string "lastname"
t.string "provider"
t.string "uid"
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
end
add_foreign_key "photos", "rooms"
end
I have used the RailsCasts Episode for orientation.
Unfortunately I am getting this Error:
How can I make this work?
Any hints for a solution are very appreciated!
Your rooms table have column distance.
And your SQL query is creating an alias distance.(AS DISTANCE).
Hence PostgreS is raising ambiguous column error.
This query is generated by gem which you are using I recommend you to change the column name of column distance to something else like my_distance or something which will not conflict with the query generated by gem.
Im attempting to rake my migrations on my heroku distro. im getting this error:
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:
PG::UndefinedTable: ERROR: relation "plants" does not exist
: ALTER TABLE "images" ADD CONSTRAINT "fk_rails_d5e1aedcb5"
FOREIGN KEY ("plant_id")
REFERENCES "plants" ("id")
Some of my tables go through, but not this one, im not sure what is even going on here. It works in development, but not in production.
Here is my schema file:
ActiveRecord::Schema.define(version: 20160521081000) do
create_table "appointments", force: :cascade do |t|
t.string "task"
t.datetime "time"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "categories", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
end
create_table "cycles", force: :cascade do |t|
t.string "title"
t.datetime "completed_at"
t.boolean "completed"
t.integer "tray_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "due_date"
end
add_index "cycles", ["tray_id"], name: "index_cycles_on_tray_id"
create_table "datalogs", force: :cascade do |t|
t.integer "tray_id"
t.float "ambcur"
t.float "ambmin"
t.float "ambmax"
t.float "folcur"
t.float "folmin"
t.float "folmax"
t.float "ph"
t.float "heatmat"
t.float "h202"
t.float "tds"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "datalogs", ["tray_id"], name: "index_datalogs_on_tray_id"
create_table "events", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "grows", force: :cascade do |t|
t.string "title"
t.text "notes"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "category_id"
t.integer "user_id"
end
create_table "images", force: :cascade do |t|
t.string "file_id"
t.integer "plant_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "tray_id"
end
add_index "images", ["plant_id"], name: "index_images_on_plant_id"
create_table "nutrient_calcs", force: :cascade do |t|
t.string "product"
t.integer "vegtime"
t.integer "flowertime"
t.float "rezsize"
t.string "rezunits"
t.boolean "aerstone"
t.string "outputunits"
t.integer "nutrient_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "nutrient_calcs", ["nutrient_id"], name: "index_nutrient_calcs_on_nutrient_id"
create_table "nutrients", force: :cascade do |t|
t.string "title"
t.string "manufacturer"
t.float "price"
t.string "unit"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "pages", force: :cascade do |t|
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "pics", force: :cascade do |t|
t.string "title"
t.text "description"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "plant_cycles", force: :cascade do |t|
t.string "title"
t.integer "interval"
t.integer "frequency"
t.integer "plant_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "plant_cycles", ["plant_id"], name: "index_plant_cycles_on_plant_id"
create_table "plantdats", force: :cascade do |t|
t.float "ambtemp"
t.float "foltempcur"
t.float "foltempmin"
t.float "foltempmax"
t.float "ph"
t.float "heatmat"
t.integer "tds"
t.float "h202"
t.integer "plant_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "ambtempmin"
t.float "ambtembmax"
end
add_index "plantdats", ["plant_id"], name: "index_plantdats_on_plant_id"
create_table "plants", force: :cascade do |t|
t.string "title"
t.text "notes"
t.integer "category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "species"
t.integer "tray_id"
t.integer "species_id"
t.integer "user_id"
end
add_index "plants", ["category_id"], name: "index_plants_on_category_id"
add_index "plants", ["tray_id"], name: "index_plants_on_tray_id"
add_index "plants", ["user_id"], name: "index_plants_on_user_id"
create_table "schedules", force: :cascade do |t|
t.integer "schedulable_id"
t.string "schedulable_type"
t.date "date"
t.time "time"
t.string "rule"
t.string "interval"
t.text "day"
t.text "day_of_week"
t.datetime "until"
t.integer "count"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "species", force: :cascade do |t|
t.string "name"
t.text "description"
t.integer "plant_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "species", ["plant_id"], name: "index_species_on_plant_id"
create_table "tasks", force: :cascade do |t|
t.integer "plant_id"
t.integer "tray_id"
t.string "title"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.datetime "due_date"
end
add_index "tasks", ["plant_id"], name: "index_tasks_on_plant_id"
add_index "tasks", ["tray_id"], name: "index_tasks_on_tray_id"
create_table "tray_cycles", force: :cascade do |t|
t.string "title"
t.integer "tray_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "tray_cycles", ["tray_id"], name: "index_tray_cycles_on_tray_id"
create_table "trays", force: :cascade do |t|
t.string "title"
t.text "notes"
t.integer "category_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.integer "rescap"
end
add_index "trays", ["category_id"], name: "index_trays_on_category_id"
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "user_id"
t.string "firstname"
t.string "lastname"
t.string "username"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
add_index "users", ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
end
Also, my app gets pushed to Heroku, but when I go to 'sign_up', I get the error from the heroku logs:
2016-05-22T07:53:31.678059+00:00 app[web.1]: ActionView::Template::Error (undefined method `firstname' for #<User:0x007fa667e33798>):
2016-05-22T07:53:31.678049+00:00 app[web.1]:
2016-05-22T07:53:31.678060+00:00 app[web.1]: 25:
2016-05-22T07:53:31.678061+00:00 app[web.1]: 26: <div class="field">
2016-05-22T07:53:31.678062+00:00 app[web.1]: 27: <%= f.label 'First Name' %><br />
2016-05-22T07:53:31.678063+00:00 app[web.1]: 28: <%= f.text_field :firstname, autofocus: true, rows: 10, cols: 10, class: 'form-control', placeholder: 'ENTER FIRST NAME' %>
2016-05-22T07:53:31.678064+00:00 app[web.1]: 29: </div>
2016-05-22T07:53:31.678065+00:00 app[web.1]: 30:
2016-05-22T07:53:31.678065+00:00 app[web.1]: 31: <div class="field">
Can anyone help me figure this out? Many thanks :)
Apparently one of the migration files got lost.
If the migration directory is quite full, or not consistent with the database you can use rake db:schema:load to directly create the whole DB.
Thanks to #xyious in the comments. Somehow a few migrations got deleted unbeknownst to me. Running heroku run rake db:schema:load
fixed the problem.
How can we combine all these resources into one feed, with the most recent submission showing at the top?
user.rb
# Returns status feed.
def feed
following_ids = "SELECT followed_id FROM relationships
WHERE follower_id = :user_id"
Habit.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
Valuation.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
Goal.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
Quantified.where("user_id IN (#{following_ids})
OR user_id = :user_id", user_id: id)
end
schema.rb
ActiveRecord::Schema.define(version: 20150311202504) do
create_table "authentications", force: true do |t|
t.integer "user_id"
t.string "provider"
t.string "uid"
t.string "index"
t.string "create"
t.string "destroy"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "days", force: true do |t|
t.integer "level_id"
t.integer "habit_id"
t.boolean "missed", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "goals", force: true do |t|
t.string "name"
t.date "deadline"
t.boolean "accomplished"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "goals", ["user_id", "created_at"], name: "index_goals_on_user_id_and_created_at"
add_index "goals", ["user_id"], name: "index_goals_on_user_id"
create_table "habits", force: true do |t|
t.datetime "left"
t.integer "level"
t.text "committed"
t.datetime "date_started"
t.string "trigger"
t.string "target"
t.string "reward"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "habits", ["user_id", "created_at"], name: "index_habits_on_user_id_and_created_at"
add_index "habits", ["user_id"], name: "index_habits_on_user_id"
create_table "levels", force: true do |t|
t.integer "user_id"
t.integer "habit_id"
t.integer "days_needed"
t.boolean "passed", default: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "quantifieds", force: true do |t|
t.string "categories"
t.string "metric"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "quantifieds", ["user_id", "created_at"], name: "index_quantifieds_on_user_id_and_created_at"
add_index "quantifieds", ["user_id"], name: "index_quantifieds_on_user_id"
create_table "relationships", force: true do |t|
t.integer "follower_id"
t.integer "followed_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "relationships", ["followed_id"], name: "index_relationships_on_followed_id"
add_index "relationships", ["follower_id", "followed_id"], name: "index_relationships_on_follower_id_and_followed_id", unique: true
add_index "relationships", ["follower_id"], name: "index_relationships_on_follower_id"
create_table "results", force: true do |t|
t.integer "user_id"
t.string "result_value"
t.date "date_value"
t.integer "quantified_id"
t.boolean "good"
t.text "comment"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
create_table "taggings", force: true do |t|
t.integer "tag_id"
t.integer "taggable_id"
t.string "taggable_type"
t.integer "tagger_id"
t.string "tagger_type"
t.string "context", limit: 128
t.datetime "created_at"
end
add_index "taggings", ["tag_id", "taggable_id", "taggable_type", "context", "tagger_id", "tagger_type"], name: "taggings_idx", unique: true
add_index "taggings", ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context"
create_table "tags", force: true do |t|
t.string "name"
t.integer "taggings_count", default: 0
end
add_index "tags", ["name"], name: "index_tags_on_name", unique: true
create_table "users", force: true do |t|
t.string "name"
t.string "email"
t.text "missed_days"
t.text "missed_levels"
t.string "provider"
t.string "uid"
t.string "oauth_token"
t.datetime "oauth_expires_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.string "remember_digest"
t.boolean "admin", default: false
t.string "activation_digest"
t.boolean "activated", default: false
t.datetime "activated_at"
t.string "reset_digest"
t.datetime "reset_sent_at"
end
add_index "users", ["email"], name: "index_users_on_email", unique: true
create_table "valuations", force: true do |t|
t.string "name"
t.text "comment"
t.boolean "private_submit"
t.integer "user_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "valuations", ["user_id", "created_at"], name: "index_valuations_on_user_id_and_created_at"
add_index "valuations", ["user_id"], name: "index_valuations_on_user_id"
end
pages_controller.rb
class PagesController < ApplicationController
def home
if logged_in?
#habits = current_user.habits.build
#valuations = current_user.valuations.build
#accomplished_goals = current_user.goals.accomplished
#unaccomplished_goals = current_user.goals.unaccomplished
#averaged_quantifieds = current_user.quantifieds.averaged
#instance_quantifieds = current_user.quantifieds.instance
#feed_items = current_user.feed.paginate(page: params[:page])
end
end
def about
end
end
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Thanks so much for your time! So far Infused's answer isn't working.
The simplest way to handle it is to combine the collections with +:
cond = ["user_id IN (#{following_ids}) OR user_id = :user_id", user_id: id]
Habit.where(cond) + Valuation.where(cond) + Goal.where(cond) + Quantified.where(cond)
As Matt Brictson mentioned in a comment, there may be a better way to aggregate the various models, but simply using + to join the collections will do the trick.