simple_form和active_attr出错

时间:2012-12-04 13:31:50

标签: ruby-on-rails ruby-on-rails-3.2 simple-form active-attr

我正在使用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 %>

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

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