ruby - Rails no route matches PUT, but rake route shows it exists -


i'm trying implement page can add quantity product in cart. tutorials on this?

so tried implementing typical edit form form_for kept giving me errors this...

<%= form_for(@cart[0]) |f| %>   <% if @cart.errors.any? %>     <div id="error_explanation">       <h2><%= pluralize(@cart.errors.count, "error") %> prohibited cart being saved:</h2>        <ul>       <% @cart.errors.full_messages.each |message| %>         <li><%= message %></li>       <% end %>       </ul>     </div>   <% end %>    <div class="actions">     <%= f.submit %>   </div> <% end %> 

and error:

no route matches {:action=>"show", :controller=>"carts", :id=>nil} missing required keys: [:id] 

...keep in mind in edit action, don't know why complaining show action. anyways have made id: false , customized primary key cart_id

in index.html file customize parameters

<td><%= link_to 'edit', edit_cart_path(cart, :id => cart.cart_id, :product_id => cart.product_id) %></td> 

this have in controller action

  def edit     @cart = cart.where(:cart_id => params[:id], :product_id => params[:product_id])   end 

and have confirmed finds correct record.

so, said screw of , decided make form_tag , send quantity parameter update action. following in edit.html

<%= form_tag('/carts', method: 'put') %>   <%= number_field_tag "quantity" %> <% end %> 

but complains there no put route, when there is...

    cart    /carts/:id(.:format)         carts#show          patch  /carts/:id(.:format)         carts#update          put    /carts/:id(.:format)         carts#update 

i imagine error there because don't have :id decided override put action following

  resources :carts, :except => 'put'     # put :carts     put "/carts" => "carts#update"   end 

but same no put route found error.

any ideas?

both of these routes:

patch  /carts/:id(.:format)         carts#update put    /carts/:id(.:format)         carts#update 

require id. id id of cart want update. cart_path(@cart.id) work or if want use string, you'll need pass id "/carts/#{@cart.id}"


Comments