1

Active Model を使用して、自分の Web サイトにお問い合わせフォームを作成しようとしています。

私が抱えている問題は、エラーメッセージが返されないことです。

リモートフォームを使用しています。

ルート:

 resource :front_contacts, only: :create, controller: :front_contact

コントローラ:

 class FrontContactController < ApplicationController
   def create
     contact = FrontContact.new(params[:front_contact])
     @errors = contact.errors.size
   end
 end

フロントコンタクト:

 class FrontContact
   include ActiveModel::Model

   attr_accessor :name, :email, :message

   validates_presence_of :name, :message
   validates_format_of :email, with: /[a-zA-Z0-9._%-]+@(?:[a-zA-Z0-9-]+\.)+(com|net|org|info|biz|me|edu|gov)/i
  end

js.erb:

  alert(<%= @errors %>);

アラートは常にアラートゼロです。

お知らせ下さい。

4

1 に答える 1