我的环境是ruby1.9.3 + rails3.2.8 + passenger。错误您需要提供至少一个验证
错误:您需要提供至少一个验证
class Post < ActiveRecord::Base
attr_accessible :content, :title, :url, :tags_attributes, :published, :category_id
has_many :comments, :dependent => :destroy
has_many :tags, :dependent => :destroy
belongs_to :category
validates :content, :presence => true
validates :title, :presence => true
validates :url, :presence => true
validates :tags_attributes, :presence => true
validates :published, :presence => true
validates :category_id, :presence => true
accepts_nested_attributes_for :tags, :allow_destroy => true,
:reject_if => proc { |attrs| attrs.all? { |k,v| v.blank? } }
scope :published, where(:published => true)
end
我控制器
class Admin::PostsController < Admin::ApplicationController
uses_tiny_mce(:options => AppConfig.default_mce_options, :only => [:new, :edit])
def index
page = params[:page]
if page == nil
page = 1
end
end
index.html.erb
<h2>Post list</h2>
<table>
<tr>
<th>Title</th>
<th>Category</th>
<th>Created</th>
<th>Updated</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.title %></td>
<td><%= post.category.title %></td>
<td><%= post.created_at.localtime.to_s(:db) %></td>
<td><%= post.updated_at.localtime.to_s(:db) %></td>
<td><%= link_to 'Edit', edit_admin_post_path(post) %></td>
<td><%= link_to 'Delete',[:admin, post], :method => :delete, :confirm => 'are you sure?' %></td>
<td></td>
</tr>
<% end %>
</table>
<br/>
<%= will_paginate @posts %>
<br/>
<%= link_to 'New Post', new_admin_post_path %>
我认为这事与rails_tiny_mce 。 之前,我的轨道插件安装它,验证是没有问题在我的写。 但我安装rails_tiny_mce后,显示错误。
我的网站是http://42.121.5.68/admin/posts.
当我更新模型
validates [:content, :title], :on => :save, :allow_blank => false,
:presence => true, :length => { :in => 10..200 }
错误是未知的验证: 'OnValidator'
这没有足够的信息。你正在执行什么操作来查看此错误?它是否显示在浏览器或日志文件中? – noodl
在浏览器中。 – andyshi
职位/索引,当我使用验证替换验证,错误是不合格的,页面是好的。但验证不起作用。 – andyshi