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 }
engineyard http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/(私のニーズに合わせて更新)で説明されているRails3コンベンションへ
resources :orders do
collection do
post :edit_individual
put :update_individual
end
end
これが私が試したことです:
次の回答で提案されているように、ルートリソースを変更しようとしました:既存のコントローラー(Ruby on Rails)にアクションを追加しましたが、同じエラーが引き続き表示されます。cancanの読み込みとリソースの承認、「resources: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"}