奇怪的路由错误

时间:2012-05-17 18:35:35

标签: ruby-on-rails-3 routing

我有一些非常奇怪的铁轨行为:

routes.rb:

resources :transactions, except: :show

佣金路线的相关输出:

       transactions GET    /transactions(.:format)                  transactions#index
                    POST   /transactions(.:format)                  transactions#create
    new_transaction GET    /transactions/new(.:format)              transactions#new
   edit_transaction GET    /transactions/:id/edit(.:format)         transactions#edit
        transaction PUT    /transactions/:id(.:format)              transactions#update
                    DELETE /transactions/:id(.:format)              transactions#destroy

视图中的代码:

<% if ( current_page?( new_transaction_path ) || current_page?( edit_transaction_path ) ) %>
  # Do something in here
<% end %>

错误:

Completed 500 Internal Server Error in 20ms

ActionController::RoutingError (No route matches {:action=>"edit", :controller=>"transactions"}):

当我删除|| current_page?( edit_transaction_path )部分时,它会起作用。

我有什么问题或者这是一个错误吗?

1 个答案:

答案 0 :(得分:2)

尝试将事务对象传递给edit_transaction_path:edit_transaction_path(@transaction)

current_page?( :action => "edit", :controller => "transactions") - 是的,这是最好的方式,我相信。