0

ユーザーモデル、Reform gem、simple_form に Devise を使用して、イベント計画チェックリスト アプリを作成しようとしています。

「/new_checklist」パスにアクセスすると、このエラー メッセージが表示され続けます: undefined method `event_date' for #< Hash:0x007fb18f5b71a8 > .

私は何を間違っていますか?さまざまな理由から、チェックリスト リソース内にユーザー リソースをネストしています。

これが私のイベントチェックリストコントローラーです:

def new_checklist
  @form = EventChecklistForm.new(event_checklist: EventChecklist.new,
                            user: User.new)
end

ユーザーモデル:

class User < ActiveRecord::Base
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
  require 'securerandom'
  has_many :checklist_items
  belongs_to :event_checklist
end

チェックリスト モデル:

class EventChecklist < ActiveRecord::Base
  has_many :checklist_items
  has_many :users
  accepts_nested_attributes_for :checklist_items
end

イベント チェックリスト フォーム モデル:

class EventChecklistForm < Reform::Form
  # include DSL
  include Reform::Form::ActiveRecord

  property :event_date, on: :event_checklist
  property :code, on: :event_checklist

  property :email, on: :user
  property :password, on: :user
  property :password_confirmation, on: :user
end

また、イベント チェックリスト モデルの末尾に「model :event_checklist」を追加しようとしましたが、違いはありませんでした。

そして最後に、フォーム:

= simple_form_for @form do |f|

  = f.input :event_date
  = f.input :code
  = f.input :email
  = f.input :password
  = f.input :password_confirmation

イベント チェックリスト モデル内に Devise ユーザー モデルをネストし、Reform gem を使用して両方を同時に作成したいと考えていました。これはできませんか?ありがとう!

4

1 に答える 1

0

同じ問題がありました。https://github.com/apotonick/reform#compositionsのハウツーに従ってください。

基本的に、次のことを行う必要があります。

class EventChecklistForm < Reform::Form
  include Composition
  ...
end
于 2014-12-16T09:23:59.183 に答える