replace send
with a different method name because it conflicts with the one defined in ruby.
TypeError: #<...> is not a symbol
-
03-06-2022 - |
Question
I cannot figure out this issue, even if it does not seem complicated...
I want to make a form to send emails in my rails app but this one does not work. I receive the following error:
TypeError in MessagesController#create
:
#<Message content: "test", email: "test@test.fr", name: "test"> is not a symbol
Error occurs in: app/controllers/messages_controller.rb:10:in 'create'
1.here is my messages_controller
:
class MessagesController < ApplicationController
def new
@message = Message.new
end
def create
@message = Message.new(params[:message])
if @message.valid?
Messenger.send(@message).deliver
redirect_to root_url, notice: "Message sent! Thank you for contacting us."
else
render "new"
end
end
end
the form
new.html.erb
:<%= form_for @message do |f| %> <%= f.text_field :name %> <%= f.text_field :email %> <%= f.text_area :content, :rows => 5 %> <%= f.submit "Send Message" %> <% end %>
the
Message
model built usingActiveAttr
:class Message include ActiveAttr::Model attribute :name attribute :email attribute :content end
My
Messenger
mailer:class Messenger < ActionMailer::Base default :from => "test@test.com" def send(message) mail(:to => "test@test.com", :subject => "test") end end
Thank you for your help!
Solution
OTHER TIPS
I had a similar TypeError using the send method, because it was expecting a symbol and I passed in something else. I fixed it by doing something like
send(some_variable) if some_variable == Symbol
However, it looks like you're trying to send mail and you're using an old way to do it. Rails 4.1.8 has a new way to do so here: http://api.rubyonrails.org/classes/ActionMailer/Base.html