Rook Rook - 1 year ago 108
Ruby Question

Rails - Event Registration Form

I am trying to create exactly the same thing explained here.

However, using

def new
@event = Event.find params[:event_id]
@registration =

I get an 'undefined method':

Started GET "/events/1/registrations/new" for ::1 at 2016-07-22 13:59:08 +0200
ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
Processing by RegistrationsController#new as HTML
Parameters: {"event_id"=>"1"}
Event Load (0.2ms) SELECT "events".* FROM "events" WHERE "events"."id" = ? LIMIT 1 [["id", 1]]
Completed 500 Internal Server Error in 30ms (ActiveRecord: 0.5ms)

NoMethodError (undefined method `registration' for #<Event:0x00000003e58bb8>
Did you mean? registrations
app/controllers/registrations_controller.rb:4:in `new'

What am I missing?

Answer Source

Assuming you have followed this

class Event < ActiveRecord::Base
   has_many :registrations

class Registration < ActiveRecord::Base
   belongs_to :event

You need to change registration to registrations

def new
  @event = Event.find params[:event_id]
  @registration =

NoMethodError (undefined method `registration' for #< Event:0x00000003e58bb8>

You have solution in your question itself ;)

Did you mean? registrations

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download