2011-07-22 124 views
1

因此,出于某种原因,我在尝试发布到该网址时收到“无路线匹配”/ accounting/payment_objects/57/comments“”。如何解决这个路由错误?

正如你从耙路径中看到的那样,这个URL是路由的。

现在这里有一些奇怪的事情,GET请求工作,但POST请求不。

另外我可以使用_path帮助器方法来生成路由。

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"} 

但是,当我张贴到它,登录返回此:

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 
+0

我在会计名称空间中实际上没有注释控制器,但我可以通过使用相同的资源路由来检索索引。 – fivetwentysix

+0

你可以发布日志与请求索引操作? – Bohdan

回答

0

发生这种情况是因为表单中有两个按钮。

其中之一必须有一个方法设置为别的东西。一种形式的

例子,可能会导致这个问题:

<%= 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 %> 

如果你改变了button_to到的link_to或将它移出形式的代码块,这应该解决您有任何问题。