Note that there are some explanatory texts on larger screens.

plurals
  1. POEdit multiple records, controller & routing
    primarykey
    data
    text
    <p>I am following railscast 198 <a href="http://railscasts.com/episodes/198-edit-multiple-individually" rel="nofollow noreferrer">http://railscasts.com/episodes/198-edit-multiple-individually</a>, trying to update it to rails 3, and am stuck with a routing error. The route <a href="http://localhost:3000/orders/edit_individual" rel="nofollow noreferrer">http://localhost:3000/orders/edit_individual</a> gives me the error:</p> <pre><code>ActiveRecord::RecordNotFound in OrdersController#show - Couldn't find Order with ID=edit_individual </code></pre> <p>I have updated and used his rails 2 routing </p> <pre><code>map.resources :products, :collection =&gt; { :edit_individual =&gt; :post, :update_individual =&gt; :put } </code></pre> <p>to the rails 3 convention as described by engineyard <a href="http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/" rel="nofollow noreferrer">http://www.engineyard.com/blog/2010/the-lowdown-on-routes-in-rails-3/</a> (updated to my needs)</p> <pre><code> resources :orders do collection do post :edit_individual put :update_individual end end </code></pre> <p>Here's what I've tried:</p> <p>I've tried changing the routes resources as suggested by the answer to: <a href="https://stackoverflow.com/questions/401241/adding-an-action-to-an-existing-controller-ruby-on-rails/401340#401340">Adding an action to an existing controller (Ruby on Rails)</a> but the same error still shows. I've tried removing the cancan load and authorize resources, the 'resources :orders' route entry, as well as the 'show' entry in the controller, but another error indicates it's still trying to show a record with ID='edit_individual' instead of treating "edit_individual" like a route. </p> <p>Here are my routes and controller, </p> <pre><code>myapp::Application.routes.draw do resources :products resources :roles devise_for :users #, :controllers =&gt; { :registrations =&gt; "registrations" } # match 'dashboard' =&gt; 'user_dashboard#index', :as =&gt; 'user_root' resources :orders do collection do post :edit_individual put :update_individual end end resources :orders class OrdersController &lt; 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 =&gt; "edit_individual" end end # ...etc. </code></pre> <p>I've removed the cancan methods, but is it the culprit still? I've tried everything I can think of and am at a dead end.. any ideas?</p> <p>edit:</p> <p>the output from command prompt:</p> <pre><code>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"=&gt;"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): </code></pre> <p>and the route in my html:</p> <pre><code> &lt;%= link_to 'Update Payments Received', edit_individual_orders_path %&gt; </code></pre> <p>and rake routes:</p> <pre><code>edit_individual_orders POST /orders/edit_individual(.:format) {:action=&gt;"edit_individual", :controller=&gt;"orders"} update_individual_orders PUT /orders/update_individual(.:format) {:action=&gt;"update_individual", :controller=&gt;"orders"} orders GET /orders(.:format) {:action=&gt;"index", :controller=&gt;"orders"} POST /orders(.:format) {:action=&gt;"create", :controller=&gt;"orders"} new_order GET /orders/new(.:format) {:action=&gt;"new", :controller=&gt;"orders"} edit_order GET /orders/:id/edit(.:format) {:action=&gt;"edit", :controller=&gt;"orders"} order GET /orders/:id(.:format) {:action=&gt;"show", :controller=&gt;"orders"} PUT /orders/:id(.:format) {:action=&gt;"update", :controller=&gt;"orders"} DELETE /orders/:id(.:format) {:action=&gt;"destroy", :controller=&gt;"orders"} </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload