我跟隨railscast 198 http://railscasts.com/episodes/198-edit-multiple-individually,試圖更新到rails 3,並堅持路由錯誤。路線http://localhost:3000/orders/edit_individual給我的錯誤:編輯多個記錄,控制器和路由
ActiveRecord::RecordNotFound in OrdersController#show - Couldn't find Order with ID=edit_individual
我已經更新了,用他的軌道2路由
map.resources :products, :collection => { :edit_individual => :post, :update_individual => :put }
到軌道3約定由EngineYard的http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/描述(更新到我的需要)
resources :orders do
collection do
post :edit_individual
put :update_individual
end
end
以下是我試過的:
我嘗試更改路由資源,建議回答如下:Adding an action to an existing controller (Ruby on Rails)但仍然顯示相同的錯誤。我嘗試刪除cancan加載和授權資源,'resource:orders'路由條目以及控制器中的'show'條目,但是另一個錯誤表明它仍在嘗試顯示ID爲'edit_individual'的記錄而不是像路線一樣對待「edit_individual」。
這裏是我的路線和控制器,
myapp::Application.routes.draw do
resources :products
resources :roles
devise_for :users #, :controllers => { :registrations => "registrations" }
# match 'dashboard' => 'user_dashboard#index', :as => 'user_root'
resources :orders do
collection do
post :edit_individual
put :update_individual
end
end
resources :orders
class OrdersController < ApplicationController
load_and_authorize_resource # cancan method
def index
end
def show
end
def edit_individual #from railscast 198
@orders = current_user.customer_orders
end
def update_individual
@orders = Order.update(params[:orders].keys, params[:orders].values).reject { |p| p.errors.empty? }
if @orders.empty?
flash[:notice] = "Orders updated"
redirect_to orders_url
else
render :action => "edit_individual"
end
end # ...etc.
我已經刪除了康康舞方法,但它是罪魁禍首還是?我已經嘗試過所有我能想到的事情,並且處於死路一條。任何想法?
編輯:
從命令提示符下輸出:
Started GET "/orders/edit_individual" for 127.0.0.1 at Thu Jun 30 11:19:02 -0700
2011
Processing by OrdersController#show as HTML
Parameters: {"id"=>"edit_individual"}
←[1m←[36mOrder Load (0.0ms)←[0m ←[1mSELECT "orders".* FROM "orders" WHERE "or
ders"."id" = 0 LIMIT 1←[0m
Completed in 2584ms
ActiveRecord::RecordNotFound (Couldn't find Order with ID=edit_individual):
,並在我的HTML路線:
<%= link_to 'Update Payments Received', edit_individual_orders_path %>
和耙路線:
edit_individual_orders POST /orders/edit_individual(.:format) {:action=>"edit_individual", :controller=>"orders"}
update_individual_orders PUT /orders/update_individual(.:format) {:action=>"update_individual", :controller=>"orders"}
orders GET /orders(.:format) {:action=>"index", :controller=>"orders"}
POST /orders(.:format) {:action=>"create", :controller=>"orders"}
new_order GET /orders/new(.:format) {:action=>"new", :controller=>"orders"}
edit_order GET /orders/:id/edit(.:format) {:action=>"edit", :controller=>"orders"}
order GET /orders/:id(.:format) {:action=>"show", :controller=>"orders"}
PUT /orders/:id(.:format) {:action=>"update", :controller=>"orders"}
DELETE /orders/:id(.:format) {:action=>"destroy", :controller=>"orders"}
是的,謝謝。請參閱我爲耙路線發佈的修改。 – thejonster
我得到了你的錯誤。看到我更新的答案。 – MKumar
它解決了錯誤嗎? – MKumar