I was creating a tableless model in Rails 4 for supporting sending emails easily.
So i have the following model:
class Message
include ActiveModel::Model
attr_accessor :subject, :content, :email
end
The following controller:
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
message = Message.new(params[:message])
if message.valid?
UserMailer.send(message)
redirect_to :back, :notice => "Email was successfully sent."
else
flash[:alert] = "You must fill all fields."
render 'new'
end
end
end
The form:
<%= form_for @message do |f| %>
<%= f.label :email %>
<%= f.text_field :email %>
<%= f.label :subject %>
<%= f.text_field :subject %>
<%= f.label :content %>
<%= f.text_area :content, rows: 5, class: 'span7' %>
<%= f.submit "Send Email", class: 'btn btn-primary' %>
<% end %>
But when i try to send an email here i what i got:
#<Message:0x007fcc98e8c760 @errors=# <ActiveModel::Errors:0x007fcc98e96788 @base=#<Message:0x007fcc98e8c760 ...>, @messages={}>, @email="sdsadas@adasdas.com", @subject="adasdas", @content="asdsad", @validation_context=nil> is not a symbol
The error says its in here UserMailer.send(message)
Can someone help me?