在rails 3中,我正在尝试实现一个简单的联系表单,但我不确定如何实现路由。
我想/ pro / contact来显示表单,但我得到了
uninitialized constant ProController::ProMessage
我的控制器:
# 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
我的路线:
match '/pro/contact' => 'pro#newpromessage', :via => :get
match '/pro/contact' => 'pro#contact', :via => :post
resources :promessages, only: [:newpromessage, :contact]
resources :promessage, only: [:newpromessage, :contact]
我的ActiveModel类:
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
我认为的标题:
<%= simple_form_for @promessage, :url => {:action => "contact"}, :method => "post" do |f| %>
答案 0 :(得分:0)
验证您的ProMessage
班级是否在app/models
目录中,名称为pro_message.rb