I have some issues with a form that is not posting and there is nothing that is shown in the logs. I am not sure if the problem comes from activemodel, file name conventions, or or routing. No messages are sent.
My controller is pretty basic it's in a file called *promessages_controller.rb*
# coding: utf-8
class PromessagesController < ApplicationController
def new
@promessage = Promessage.new
end
def create
@promessage = Promessage.new(params[:promessage])
if @promessage.valid?
PromessageMailer.contact_us(@promessage).deliver
redirect_to(root_path, :notice => "Sent.")
else
redirect_to(root_path, :notice => "Error")
end
end
end
My mailer is in a file called *promessage_mailer.rb*
class PromessageMailer < ActionMailer::Base
def contact_us(message)
@message = message
mail(:to => 'xxx@gmail.com', :subject => "test", :from => "info@mydomain.com")
end
end
My activemodel model is in a file called promessage.rb and contains the following:
class Promessage
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :email, :name, :body
validates :name, :email, :body, :presence => true
validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
My form is in new.html.erb and is under views/promessages
<%= simple_form_for @promessage do |f| %>
<% @promessage.errors.full_messages.each do |msg| %>
<p><%= msg %></p>
<% end %>
<%= f.input :email, label: 'email' %>
<%= f.input :body, label: 'text', as: :text, :input_html => { :cols => 50, :rows => 5 } %>
<%= f.submit "Send", :class => 'btn btn-primary' %>
<% end %>
I have my text and html templates in views/promessage_mailer
and in my routes I added:
resources :promessages, only: [:new, :create]
Everytime I submit the form, it shows the error in the controller and doesn't even validate the form. What am I missing?