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

このエラーは、v0.7.0 で修正された active_attr のバグが原因でした。アップグレードすると問題が解決します。

于 2013-03-14T13:42:57.853 に答える
0

どうやら、 https://github.com/plataformatec/simple_form/wiki/Twitter-Bootstrap-v2-and-simple_form-v2にあるように、Twitter ブートストラップ用のラップされたボタンを作成するために追加した機能が壊れてしまいました。

于 2012-12-04T14:01:21.013 に答える