【发布时间】:2016-08-04 07:07:10
【问题描述】:
我的表单字段验证遇到了一些问题。我有两个文本字段需要验证才能持续到下一页。验证运行正确,但验证消息显示为 rails 错误。
任何人都知道为什么它的显示像 rails 错误。
型号:
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
我还有两个表单来验证字段。在这种形式中,验证错误会正确显示。
【问题讨论】:
标签: ruby-on-rails ruby validation