In rails 3, I'm trying to implement a simple contact form but I am unsure how to implement the routing.
I would like /pro/contact to show the form but I get an
uninitialized constant ProController::ProMessage
My controller:
# coding: utf-8
class ProController < ApplicationController
def newpromessage
@promessage = ProMessage.new
end
def contact
@promessage = ProMessage.new(params[:message])
@string = params[:receiver]
if @promessage.valid?
ProMailer.contact_us(@message, @string).deliver
redirect_to(root_path, :notice => "Sent.")
else
redirect_to(root_path, :notice => "Error.")
end
end
end
My routes:
match '/pro/contact' => 'pro#newpromessage', :via => :get
match '/pro/contact' => 'pro#contact', :via => :post
resources :promessages, only: [:newpromessage, :contact]
resources :promessage, only: [:newpromessage, :contact]
My ActiveModel class:
class ProMessage
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :name, :email, :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
The from header of my view:
<%= simple_form_for @promessage, :url => {:action => "contact"}, :method => "post" do |f| %>