I am using active_attr and simple_form.
When I navigate to the page that should show my form I get the following error:
undefined method `new_record?' for #<Message body: nil, email: nil, name: nil, subject: nil>
Here is my model:
class Message
include ActiveAttr::Model
attribute :name
attribute :email
attribute :subject
attribute :body
validates :name, :email, :subject, :body, :presence => true
validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true
end
My Controller:
class ContactController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
NotificationsMailer.new_message(@message).deliver
redirect_to(root_path, :notice => "Message was successfully sent.")
else
flash.now.alert = "Please fill all fields."
render :new
end
end
end
And finally my view:
<%= simple_form_for @message, :url => contact_path do |f| %>
<%= f.input :name %>
<%= f.input :email %>
<%= f.input :subject %>
<%= f.input :body %>
<%= f.button :wrapped, :submit %>
<% end %>