2016-04-13 9 views
-1

フォームフィールドの検証に問題があります。次のページに進む前に検証が必要な2つのテキストフィールドがあります。検証は正しく実行されますが、検証メッセージはrailsエラーのように表示されます。フィールド検証Ruby on Rails

enter image description here

しかし、私はenter image description here以下

のようなこのエラーはいずれかがレール・エラーなどの理由その番組を知ってほしいです。

モデル:

class Assignment < ActiveRecord::Base 
    include Workflow 

    belongs_to :folder 
    belongs_to :employee 

    after_initialize :init_start_dateenter code here 

    validates_presence_of :folder_id, :employee_id 
end 

コントローラー:

class AssignmentsController < ApplicationController 
    def create 
    @assignment = Assignment.new(assignment_params) 

    respond_to do |format| 
     if @assignment.save! 
     format.html { redirect_to @assignment, notice: 'Assignment was successfully created.' } 
     format.json { render :show, status: :created, location: @assignment } 
     @assignment.folder.update({status: 'assigned'}) 
     else 
     format.html { render :new } 
     format.json { render json: @assignment.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

end 

私はフィールドを検証するために2つの以上のフォームを持っています。そのフォームでは、検証エラーが正しく表示されます。

答えて

2

あなたは、これはあなたが!を省略した場合、それは単純にブール値を返します(し、エラーまたは成功をレンダリングします、そのライン上のエラーがスローされますよう、保存から!を削除する必要があります。

ので

class AssignmentsController < ApplicationController 
    def create 
    @assignment = Assignment.new(assignment_params) 

    respond_to do |format| 
     if @assignment.save 
     format.html { redirect_to @assignment, notice: 'Assignment was successfully created.' } 
     format.json { render :show, status: :created, location: @assignment } 
     @assignment.folder.update({status: 'assigned'}) 
     else 
     format.html { render :new } 
     format.json { render json: @assignment.errors, status: :unprocessable_entity } 
     end 
    end 
    end 

end 
+0

ありがとうJames Watling :)それは私のミスです – ArpithaGeorge

関連する問題