1
我有一個模型叫RateIndex
工作:軌道4 - 驗證沒有一個模型
class RateIndex < ActiveRecord::Base
belongs_to :user
belongs_to :car
validates :name, :presence => true
validates :car_name, :presence => true
validates :description, :presence => true
...
end
控制器是rate_indices_controller.rb
class RateIndicesController < ApplicationController
def new
@rate_index = RateIndex.new
end
...
而且形式:
<%= form_for(@rate_index) do |f| %>
<% if @rate_index.errors.any? %>
<div id="error_explanation">
<h3><%= "#{pluralize(@rate_index.errors.count, "error")} prohibited this game from being saved:" %></h3>
<ul>
<% @rate_index.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
...
但是,當我發送空的表單時,沒有顯示驗證錯誤...我試圖改變驗證規則s,但即使如此,他們也被忽略了。
我對它很盲目,對它進行了很長時間的研究,但仍然沒有任何結果。
我會很感激這裏的每一個幫助。
謝謝
編輯:
def create
@rate_index = RateIndex.new(rate_index_params)
respond_to do |format|
if @rate_index.save
format.html { redirect_to '/rate_indices/new', notice: 'Rate was successfully added.' }
format.json { render action: 'show', status: :created, location: @rate_index }
else
format.html { render action: 'new' }
format.json { render json: @rate_index.errors, status: :unprocessable_entity }
end
end
end
請,加上'ReateIndex#create'行動對你的問題。 – Rodrigo 2015-02-10 17:50:00
@Rodrigo - 加了,謝謝。 – user984621 2015-02-10 18:03:29
模型是否成功保存或僅顯示任何消息? – BroiSatse 2015-02-10 18:04:58