Apologies for the question, I'm still learning rails. Trying to update a specific user's home cities through a drop down. I followed all the steps as outlined in this question How to have a drop down <select> field in a rails form? and I'm not getting any errors. However, when I go to my rails console and do User.first - the homecities_id is still set as nil. Thank you guys so much for your help.
edit.html.erb
<div class="field">
<%= f.label :homecity %><br>
<%= f.collection_select :homecities_id, Homecity.all, :id, :Hometown %>
</div>
User.rb
class User < ApplicationRecord
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable,
:validatable, :omniauthable, omniauth_providers: [:facebook]
cattr_accessor :current_user
belongs_to :homecity, optional: true
end
Homecity.rb
class Homecity < ApplicationRecord
has_many :users
end
Application_controller.rb
class ApplicationController < ActionController::Base
def configure_permitted_parameters
devise_parameter_sanitizer.permit(:sign_up, keys: [:username, :name, :avatar, :homecities])
devise_parameter_sanitizer.permit(:account_update, keys: [:username,:name, :avatar, :homecities])
end
end
Migrations
class CreateHomecities < ActiveRecord::Migration[5.0]
def change
create_table :homecities do |t|
t.string :Hometown
t.timestamps
end
end
end
class AddHomecitiesRefToUsers < ActiveRecord::Migration[5.0]
def change
add_reference :users, :homecities, foreign_key: true
end
end
seed.rb
Homecity.destroy_all
bigapple = Homecity.create!(Hometown:"New York City")
techhub = Homecity.create!(Hometown:"San Francisco")
longhorns = Homecity.create!(Hometown:"Austin")
angels = Homecity.create!(Hometown:"Los Angeles")
windycity = Homecity.create!(Hometown:"Chicago")
hcards = Homecity.create!(Hometown:"Washington DC")
amazon = Homecity.create!(Hometown:"Seattle")