Reputation: 1
first time posting. Im trying to make mailgun send me an email for new subscribers but when i filled the form it gives me 500 internal server error and TypeError.
Completed 500 Internal Server Error in 13ms (ActiveRecord: 4.9ms) TypeError (no implicit conversion of Symbol into Integer):
app/controllers/contacts_controller.rb:9:in[]' app/controllers/contacts_controller.rb:9:in
create'
Is there something wrong with my ContactsController?
class ContactsController < ApplicationController
def new
@contact = Contact.new
end
def create
@contact = Contact.new(contact_params)
if @contact.save
name = params[:contact][:name]
email = params[:contact][:email]
body = params[:contact][:comments]
ContactMailer.contact_email(name, email, body).deliver
flash[:success] = "Message sent."
redirect_to new_contact_path
else
flash[:danger] = @contact.errors.full_messages.join(", ")
redirect_to new_contact_path
end
end
private
def contact_params
params.require(:contact).permit(:name, :email, :comments)
end
end
<!DOCTYPE html>
<html>
<head></head>
<body>
<p>You have received a message from the site's contact form, from
<%= "#{ @name }, #{ @email }." %></p>
<p><%= @body %></p>
</body>
</html>
The weird thing is that if i run my codes in development via cloud9 server it runs fine but in production via heroku server it gives me an error after trying to submit the contact us form fully filled out. Also im learning how to code by following this website. The issue is with lesson 78.
Upvotes: 0
Views: 193
Reputation: 72
name, email, body - have to be string.
inspect it by
name.class
email.class
body.class
ActionMailer can work only with basic types(like string), but in you code someone in name, email, body is a symbol class.
Upvotes: -1