This error is coming up after pressing submit on my form saving to db as I'm taking a course in Ruby. I have also already attempted rake:db
migrate to no avail.
ActiveRecord::UnknownAttributeError in ContactsController#create
unknown attribute: comments
Extracted source (around line #7): 5 6 7 8 9 10
def create @contact = Contact.new(contact_params)
if @contact.save
redirect_to new_contact_path, notice: "Message sent."
my contact controler.rb code
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(contact_params)
if @contact.save
redirect_to new_contact_path, notice: "Message sent."
else
redirect_to new_contact_path, notice: "Error occurred."
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
My contact.rb
class Contact < ActiveRecord::Base
def name
end
def email
end
def comments
end
end
--------------
class CreateContacts < ActiveRecord::Migration
def change
create_table :contacts do |t|
t.string :name
t.string :email
t.text :commments
t.timestamps
end
end
end