Rails 5.0.0.1で開発しています。
lesson
モデルのsituation
カラムをcheck_box
で複数選択できる要件としており、new/create
はできるのですが、edit
時にwrong argument type nil (expected Regexp)
といったエラーが出てしまいます。解決策わからず、お分かりの方、ご教示頂けますと大変助かります。
ruby
1#LessonModelとTable 2 3# Table name: lessons 4# 5# id :integer not null, primary key 6# situation :string 7# created_at :datetime not null 8# updated_at :datetime not null 9 10class Lesson < ApplicationRecord 11 before_save do 12 self.situation.gsub!(/[\[\]\"]/, "") if attribute_present?("situation") 13 end 14end
ruby
1#lessons_helper.rb 2module LessonsHelper 3 def checked(area) 4 @lesson.situation.nil? ? false : @lesson.situation.match(area) 5 end 6end
ruby
1#_form.html.erb 2<%= f.label :situation, 'シチュエーション' %> 3<%= check_box_tag 'lesson[situation][]', 'date', checked(`date`), id: 'situation_date'%> 4<%= label_tag 'situation_date', 'date' %>  5 6<%= check_box_tag 'lesson[situation][]', 'interview', checked(`interview`), id: 'situation_interview'%> 7<%= label_tag 'situation_interview', 'interview' %> 8 9<%= check_box_tag 'lesson[situation][]', 'party', checked(`party`), id: 'situation_party'%> 10<%= label_tag 'situation_party', 'party' %>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。