Reform gem to create Devise user nested within Checklist resource -- is this possible?

503 views Asked by At

I'm trying to create an event planning checklist app using Devise for the user model, the Reform gem, and simple_form.

I keep seeing this error message when I access the '/new_checklist' path: undefined method `event_date' for #< Hash:0x007fb18f5b71a8 >.

What am I doing wrong? For various reasons, I have my user resource nested within my checklist resource.

Here's my event checklist controller:

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

User model:

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

Checklist model:

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

Event checklist form model:

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

I've also tried adding "model :event_checklist" to the end of the event checklist model, but it didn't make a difference.

And finally, the form:

= simple_form_for @form do |f|

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

I had hoped to nest the Devise user model within the event checklist model, and create both at the same time using the Reform gem. Can this not be done? Thanks!

1

There are 1 answers

1
Michael On

Had the same issue. Follow the howto on https://github.com/apotonick/reform#compositions.

Basically you have to:

class EventChecklistForm < Reform::Form
  include Composition
  ...
end