0

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

路线.rb:

resources :transactions, except: :show

rake 路由的相关输出:

       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 )零件时它起作用。

我有什么问题还是这是一个错误?

4

1 回答 1

2

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

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

于 2012-05-17T20:23:01.987 回答