メール メッセージを表す ActiveModel クラスと、useremail の非表示フィールドを含むメッセージを送信するフォームがあります。フォームを送信すると、
undefined method `receiver=' for <Message:0x007fce44d495f8>
.
class Message
extend ActiveModel::Naming
include ActiveModel::Conversion
include ActiveModel::Validations
include ActionView::Helpers::TextHelper
attr_accessor :name, :email, :contenu
validates :name,
:presence => true
validates :email,
:format => { :with => /\b[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}\z/ }
validates :content,
:length => { :minimum => 10, :maximum => 1000 }
def initialize(attributes = {})
attributes.each do |name, value|
send("#{name}=", value)
end
end
def persisted?
false
end
end
私のフォーム:
<%= form_for @message, :url => {:action => "contact"}, :method => "post" do |f| %>
<% @message.errors.full_messages.each do |msg| %>
<p><%= msg %></p>
<% end %>
<%= f.hidden_field :receiver, :value => @listing.user.email %>
<p>
<%= f.label :name %><br />
<%= f.text_field :name %>
</p>
<p>
<%= f.label :email %><br />
<%= f.text_field :email %>
</p>
<p>
<%= f.label :contenu, "Message" %><br />
<%= f.text_area :contenu %>
</p>
<p><%= f.submit "Send Message" %></p>
<% end %>