2011-07-22 67 views
1

なんらかの理由で、そのURLに投稿しようとしたときに、「経路の一致はありません」/ accounting/payment_objects/57 /コメントが届いています。このルーティングエラーを解決するにはどうすればよいですか?

rakeルートからわかるように、その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) 

私はこれが私のコントローラ/アクションとは何の関係もありません確認しています。

しかし、ここでは、この問題に関連するroute.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

私は実際にaccounting名前空間にコメントコントローラを持っていませんが、同じリソースルートを使用してインデックスを取得できます。 – fivetwentysix

+0

インデックスアクションのリクエストでログを投稿できますか? – Bohdan

答えて

0

これは、フォームに2つのボタンがあるために起こっていました。

これらのうちの1つは、メソッドを別のものに設定する必要があります。この問題を引き起こす可能性があり、フォームの

例:

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

あなたがのlink_toにbutton_toを変更したり、フォームブロックの外に移動した場合、これはあなたが持っているすべての問題を解決する必要があります。

関連する問題