アソシエーションが組めていないためかidが流れていない状態かと思っています。
が、解決が私には難しく、お力をお借りできれば幸いです。
ruby -v: ruby 2.6.5p114 (2019-10-01 revision 67812) [x86_64-darwin20]
rails -v: Rails 6.0.3.6
gem -v: 3.0.3
試したこと
再bundle install
rails c
irb(main):001:0> @area_record_1
=> nil
irb(main):002:0> @area
=> nil
確認
routes.rb
devise_for :users root to: "youtube_vact#index" resources :youtube_vact , only: [:new, :create, :index, :show] do resource :user_skills, only: [:edit] end end
models/user_skill.rb
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validates :name, presence: true has_many :user_skills end
models/user.rb
class User < ApplicationRecord # Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable validates :name, presence: true has_many :user_skills end
edit.html.erb
<form class="form" action="#" method="post"> <textarea name="introduction" cols="30" rows="5"></textarea></p> <div class="form-group"> <label for="password">エリア</label> <%= f.collection_select(:area_id, Area.all, :id, :name, {}, {class:"select-box", id:"user-area"}) %> </div> <p><input type="submit" value="編集完了"></p> </form>
models/area.rb
class Area < ActiveHash::Base self.data = [ {id: 1, name: '--'}, {id: 2, name: '北海道'}, {id: 3, name: '青森県'}, {id: 4, name: '岩手県'}, {id: 5, name: '宮城県'}, {id: 6, name: '秋田県'}, {id: 7, name: '山形県'}, {id: 8, name: '福島県'}, {id: 9, name: '茨城県'}, {id: 10, name: '栃木県'}, {id: 11, name: '群馬県'}, {id:12, name: '埼玉県'}, {id:13, name: '千葉県'}, {id: 14, name: '東京都'}, {id: 15, name: '神奈川県'}, {id: 16, name: '新潟県'}, {id: 17, name: '富山県'}, {id: 18, name: '石川県'}, {id: 19, name: '福井県'}, {id: 20, name: '山梨県'}, {id: 21, name: '長野県'}, {id: 22, name: '岐阜県'}, {id: 23, name: '静岡県'}, {id: 24, name: '愛知県'}, {id: 25, name: '三重県'}, {id: 26, name: '滋賀県'}, {id: 27, name: '京都府'}, {id: 28, name: '大阪府'}, {id: 29, name: '兵庫県'}, {id: 30, name: '奈良県'}, {id: 31, name: '和歌山県'}, {id: 32, name: '鳥取県'}, {id: 33, name: '島根県'}, {id: 34, name: '岡山県'}, {id: 35, name: '広島県'}, {id: 36, name: '山口県'}, {id: 37, name: '徳島県'}, {id: 38, name: '香川県'}, {id: 39, name: '愛媛県'}, {id: 40, name: '高知県'}, {id: 41, name: '福岡県'}, {id: 42, name: '佐賀県'}, {id: 43, name: '長崎県'}, {id: 44, name: '熊本県'}, {id: 45, name: '大分県'}, {id: 46, name: '宮崎県'}, {id: 47, name: '鹿児島県'}, {id: 48, name: '沖縄県'} ] include ActiveHash::Associations has_many :user_skills end