0

我正在使用 active_attr 和 simple_form。

当我导航到应该显示我的表单的页面时,我收到以下错误:

undefined method `new_record?' for #<Message body: nil, email: nil, name: nil, subject: nil>

这是我的模型:

class Message

  include ActiveAttr::Model

  attribute :name
  attribute :email
  attribute :subject
  attribute :body

  validates :name, :email, :subject, :body, :presence => true
  validates :email, :format => { :with => %r{.+@.+\..+} }, :allow_blank => true

end

我的控制器:

class ContactController < ApplicationController
  def new
    @message = Message.new
  end

  def create
    @message = Message.new(params[:message])

    if @message.valid?
      NotificationsMailer.new_message(@message).deliver
      redirect_to(root_path, :notice => "Message was successfully sent.")
    else
      flash.now.alert = "Please fill all fields."
      render :new
    end
  end
end

最后是我的观点:

<%= simple_form_for @message, :url => contact_path do |f| %> 
  <%= f.input :name %>
  <%= f.input :email %>
  <%= f.input :subject %>
  <%= f.input :body %>
  <%= f.button :wrapped, :submit %>
<% end %>
4

2 回答 2

0

显然,我在https://github.com/plataformatec/simple_form/wiki/Twitter-Bootstrap-v2-and-simple_form-v2上找到的为 twitter 引导程序制作包装按钮的额外功能打破了它。

于 2012-12-04T14:01:21.013 回答
0

此错误是由于在 v0.7.0 中修复的 active_attr 中的错误造成的。升级解决了这个问题。

于 2013-03-14T13:42:57.853 回答