Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.2提交有很多:通过表单触发器验证_Ruby On Rails_Validation_Ruby On Rails 3.2 - Fatal编程技术网

Ruby on rails Rails 3.2提交有很多:通过表单触发器验证

Ruby on rails Rails 3.2提交有很多:通过表单触发器验证,ruby-on-rails,validation,ruby-on-rails-3.2,Ruby On Rails,Validation,Ruby On Rails 3.2,奇怪的错误,我以前从未遇到过。如果我提交一个多对多表单,它将触发has_many:through关系中某个模型的验证。当我进行验证时,表单提交ok。为什么验证会阻止一个has_many:through表单提交?这是信息 class Client has_many :client_routes has_many :routes, :through => :client_routes #plus many validations below end class Route h

奇怪的错误,我以前从未遇到过。如果我提交一个多对多表单,它将触发has_many:through关系中某个模型的验证。当我进行验证时,表单提交ok。为什么验证会阻止一个has_many:through表单提交?这是信息

class Client
  has_many :client_routes
  has_many :routes, :through => :client_routes
  #plus many validations below
end

class Route
  has_many :client_routes
  has_many :clients, :through => :client_routes
end

class ClientRoute
  belongs_to :client
  belongs_to :route
在创建路由的表单中,我有一个ul div,用于拖放以下隐藏字段。这些隐藏字段通过一系列客户端循环

<%= hidden_field_tag("route[client_ids][]", c.id) %>
以下是一个表格,其中部分是一个用于拖放的空ul:

<%= form_for Route.new, :remote => true do |f| %>

  <p>
    <%= f.label :name %>    <br/>
    <%= f.text_field :name %>
  </p>
  <p>
    <%= f.label :mileage %> <br/>
    <%= f.text_field :mileage %>
  </p>
  <p>
    <%= f.label :rate %>         <br/>
    <%= f.text_field :rate %>
  </p>
  <p>
    <%= f.submit %>
  </p>
  <div class="assign_clients">
    <%= render :partial => "client_routes" %>
  </div>

<% end %>
另一个有效的测试是我添加了以下跳过验证的测试,但是这个结果现在跳过了我对路由模型的验证

if @route.save(:validation => false)   

您可以发布表单吗?@Zajn我添加了您请求的信息。您如何将
客户端添加到新的
路线
?很明显,您的表单未通过与新的
路由相关联的
客户端
未满足其验证要求。如果与其关联的对象也无效,
路由
对象将不会保存。您能否详细说明如何将
客户端
添加到
路由
?重点是表单不应调用客户端验证。我只是将client_id添加到一个名为client_routes的查找表中。当rails检测到上述约定中的隐藏字段时,它会自动将客户机id和关联的路由id保存到该表中。我正在使用拖放来用客户端填充空的ul元素,该数组与表单一起提交。@Zajn我现在明白你的意思了。在将验证添加到客户机模型之前,我在数据库中创建了一些记录。我假设只有在该模型上创建记录时才使用验证。我不相信有多少人意识到这种行为,所以请把这句话写在回答中
def create
  @route = Route.new(params[:route])
  if @route.save
    respond_with @route, :location => routes_url
  else
    flash[:notice]= "Not saved due to your incompetence"
  end
end
if @route.save(:validation => false)