###前提・実現したいこと
DBと紐付かないモデルを作成し,include ActiveModel::Modelでお問い合わせのためのモデルを作りました。
いくつかお問い合わせのためのページが存在するので,それごとにモデルを作らずにまとめて一つのモデルで管理し,ページごとに異なるバリデーションに対応させようと考えていましたが,NomethodErrorなどのエラーのためうまく分岐できません。
###発生している問題・エラーメッセージ
ruby
1undefined local variable or method `params' for Inquiry:Class
###該当のソースコード
ruby
1class Inquiry 2 include ActiveModel::Model 3 4 attr_accessor :detail_id,:name,:name_kana, :email,:email_confirmation, :message,:contents,:address,:zip1,:zip2,:phone, :mobile,:fax,:contact_time,:contact_method,:occupation,:reserve_date,:shop_id,:agreement,:number 5 6 with_options if: self.action_name = 'reservation' 7 #バリデーションの内容 8 end 9 10end 11 12page_controller.rb 13 14 def reservation 15 # 入力画面を表示 16 @inquiry = Inquiry.new 17 @readonly = false 18 render :action => 'reservation' 19 end 20 21 def reservation_confirm 22 @inquiry = Inquiry.new(params[:inquiry]) 23 if @inquiry.valid? 24 @readonly = true 25 render :action => 'reservation_confirm' 26 else 27 render :action => 'reservation' 28 end 29 end 30 31 def reservation_thanks 32 # メール送信 33 @inquiry = Inquiry.new(params[:inquiry]) 34 InquiryMailer.received_email(@inquiry).deliver 35 InquiryMailer.admin_email(@inquiry).deliver 36 # 完了画面を表示 37 render :action => 'reservation_thanks' 38 end 39 40 41
###試したこと
たとえば、やりかたはよくないとおもいますが、ページごとにhiddenでデータを送るなどを検証してみましたが、うまくデータを取得することができませんでした。
やはりモデルを別にするべきでしょうか?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/10/08 05:55