Issue with geocoder using postgresql - ruby-on-rails

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.

Related

Relation does not exist when deploying to heroku

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

Rails how do I extract (and copy) only certain attributes from an ActiveRecord object?

In Rails 5, I want to create a new instance of an Author model, but in the process I want to copy only a subset of the attribute values (columns) from my User model.
I am trying to run the following code:
user = User.first
Author.create user.attributes.without("id", "token", "secret", "created_at", "updated_at", "active", "email", "encrypted_password", "first_name", "last_name", "reset_password_token", "reset_password_sent_at", "remember_created_at", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip")
The User.first method works and returns a valid user from the table. However, the Author.create line doesn't work. I'm getting a NoMethodError: undefined method `each' for nil:NilClass error.
Here is my User table from the schema.rb file:
create_table "users", force: :cascade do |t|
t.string "provider", null: false
t.string "uid", null: false
t.string "name"
t.string "location"
t.string "image_url"
t.string "url"
t.string "token"
t.string "secret"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.boolean "active", default: false
t.text "description"
t.string "screen_name"
t.integer "followers"
t.integer "following"
t.integer "statuses"
t.integer "listed"
t.integer "lists"
t.integer "favorites"
t.integer "views", default: 0
t.string "website"
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "first_name", default: "", null: false
t.string "last_name", 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.index ["active"], name: "index_users_on_active", using: :btree
t.index ["email"], name: "index_users_on_email", unique: true, using: :btree
t.index ["provider", "uid"], name: "index_users_on_provider_and_uid", unique: true, using: :btree
t.index ["provider"], name: "index_users_on_provider", using: :btree
t.index ["uid"], name: "index_users_on_uid", using: :btree
end
And here is my Author table:
create_table "authors", force: :cascade do |t|
t.string "uid", null: false
t.string "provider", null: false
t.string "name"
t.string "location"
t.string "image_url"
t.string "url"
t.text "description"
t.string "screen_name"
t.integer "followers", default: 0
t.integer "following", default: 0
t.integer "statuses", default: 0
t.integer "listed", default: 0
t.integer "lists", default: 0
t.integer "favorites", default: 0
t.integer "views", default: 0
t.string "website"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["provider"], name: "index_authors_on_provider", using: :btree
t.index ["uid", "provider"], name: "index_authors_on_uid_and_provider", unique: true, using: :btree
t.index ["uid"], name: "index_authors_on_uid", using: :btree
end
As you can see, the new Author table has many of the same columns/attributes as the User table, but I only want to copy across a subset of the User attributes (columns and values) when creating the new Author object.
Maybe the user.attributes.without method isn't the right one?
You can do it via slice since user.attributes is just a hash of values.
user.attributes.slice('name', 'location')

Rails join on user column

I'm trying to get all Activities related to users of the same school (a string on the user object), but the error I'm getting is this:
Can't join 'Activity' to association named 'users'; perhaps you
misspelled it?
activity_controller.rb
#school = current_user.school
#bathroom = Activity.includes(:users).where(name: 'Bathroom').where( :user => { :school => #school} )
and the schema:
create_table "activities", force: :cascade do |t|
t.string "name"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "student_id"
t.string "status"
t.integer "user_id"
t.index ["student_id"], name: "index_activities_on_student_id"
t.index ["user_id"], name: "index_activities_on_user_id"
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.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.string "grade"
t.string "school"
t.integer "maxout"
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
Not users but user because Activity belongs to User
#bathroom = Activity.includes(:user).where(name: 'Bathroom').where( :users => { :school => #school} )
But User has many activities so User.includes(:activities)
Of course, you have to provide associations:
class Activity
belongs_to :user
class User
has_many :activities

Errors when migrating heroku

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.

Schema file in rails app wont update anymore

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.).

Resources