Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/58.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 如何解决这个路由错误?_Ruby On Rails_Routing - Fatal编程技术网

Ruby on rails 如何解决这个路由错误?

Ruby on rails 如何解决这个路由错误?,ruby-on-rails,routing,Ruby On Rails,Routing,因此,出于某种原因,我在尝试发布到该url时没有收到任何路由匹配/记帐/付款对象/57/注释 正如您可以从rake路由中看到的,该url是路由的 现在有点奇怪,GET请求有效,但POST请求无效 我还可以使用_pathhelper方法生成路由 accounting_payment_object_comments GET /accounting/payment_objects/:payment_object_id/comments(.:format)

因此,出于某种原因,我在尝试发布到该url时没有收到任何路由匹配/记帐/付款对象/57/注释

正如您可以从rake路由中看到的,该url是路由的

现在有点奇怪,GET请求有效,但POST请求无效

我还可以使用_pathhelper方法生成路由

accounting_payment_object_comments GET    /accounting/payment_objects/:payment_object_id/comments(.:format)                             {:action=>"index", :controller=>"accounting/comments"}
                                   POST   /accounting/payment_objects/:payment_object_id/comments(.:format)                             {:action=>"create", :controller=>"accounting/comments"}
但当我发布到它时,log会返回以下内容:

Started POST "/accounting/payment_objects/57/comments" for 127.0.0.1 at Fri Jul 22 14:53:58 +0800 2011

ActionController::RoutingError (No route matches "/accounting/payment_objects/57/comments"):


Rendered /Users/pma/.rvm/gems/ree-1.8.7-2010.02/gems/actionpack-3.0.9/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.7ms)
我已确认这与我的控制器/操作无关

但我的routes.rb中有一段代码与此问题相关

  namespace 'accounting' do
    resource :requisitions, :only => [:show] do
      collection do
        get 'filter'
      end
    end
    resource :purchase_orders, :only => [:show]
    resource :accounts_payable, :only => [:show]
    resource :payment_requests, :only => [:show, :update]
    resource :general_ledger, :only => [:show]
    resource :permissions, :only => [:update]

    resources :payment_objects do
      collection do
        get 'filter'
        post 'permissions'
      end
      member do
        match 'approve'
        match 'decline'
      end
      resources :items do
        member do
          get 'receive' => 'items#received_form'
          post 'receive' => 'items#process_received_form'
        end
        resources :receiving_records, :only => [:create, :new]
      end
      resources :files
      resources :comments, :except => [:show, :new]
    end
  end

这是因为表单中有两个按钮

其中一个方法必须设置为其他方法

可能导致此问题的表单示例:

<%= form_for @comment, :url => @create_url, :method => :post do |f| %>
  <%= f.text_area :content %>
  <div class="space inline">
    <%= f.submit %>
    <%= button_to 'Discard Draft', @discard_url, :id => 'discard_draft_link', :method => :delete %>
    <p id="draft_save_message">
      <% if @draft %>
        Draft was last saved at: <%= @draft.updated_at.getlocal %>
      <% else %>
        Draft not saved yet.
      <% end %>
    </p>
  </div>
<% end %>

如果您将按钮更改为链接或将其移出表单块,这将解决您遇到的任何问题。

我在记帐命名空间中实际上没有注释控制器,但我可以使用相同的资源路由检索索引。您是否可以发布带有索引操作请求的日志?