Note that there are some explanatory texts on larger screens.

plurals
  1. PObutton_to not passing correct id from params hash
    primarykey
    data
    text
    <p>The button_to is not passing the correct id to the line_item. In the log below you see the bike_id change from the correct '86' to the incorrect '1' (which coincidentally is my user_id). Any help would be appreciated. Below is the error from my development.log, then the code from my view and controllers. Thanks.</p> <p><strong>development.log</strong></p> <p><code>Started POST "/line_items?bike_id=86" for 127.0.0.1 at 2011-08-01 18:09:52 -0400</code></p> <p><code>DEPRECATION WARNING: Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead. (called from &lt;class:ApplicationController&gt; at /Users/willdennis/rails_projects/spinlister/app/controllers/application_controller.rb:8)</code></p> <p><code>Processing by LineItemsController#create as HTML</code></p> <p><code>Parameters: {"authenticity_token"=&gt;"5GYQqvf7U5awhLrZ9Aw910ETf2kqOk3PI315jkjEfMU=", "bike_id"=&gt;"86"}</code></p> <p><code>[1m[35mCart Load (0.6ms)[0m SELECT "carts".* FROM "carts" WHERE ("carts"."id" = 8) LIMIT 1 [1m[36mBike Load (1.2ms)[0m [1mSELECT "bikes".* FROM "bikes" WHERE ("bikes"."id" = 86) ORDER BY bikes.created_at DESC LIMIT 1[0m [1m[35mSQL (0.5ms)[0m INSERT INTO "line_items" ("bike_id", "cart_id", "created_at", "updated_at") VALUES (1, 8, '2011-08-01 22:09:53.208978', '2011-08-01 22:09:53.208978') [1m[36mCart Load (1.5ms)[0m [1mSELECT "carts".* FROM "carts" WHERE ("carts"."id" = 8) LIMIT 1[0m Redirected to <a href="http://localhost:3000/carts/8" rel="nofollow">http://localhost:3000/carts/8</a> Completed 302 Found in 251ms</code></p> <p><strong>line_items_controller.rb</strong></p> <pre><code>def create @cart = current_cart @bike = Bike.find(params[:bike_id]) @line_item = @cart.line_items.build(:bike_id =&gt; @bike) respond_to do |format| if @line_item.save format.html { redirect_to(@line_item.cart, :notice =&gt; 'Line item was successfully created.') } format.xml { render :xml =&gt; @line_item, :status =&gt; :created, :location =&gt; @line_item } else format.html { render :action =&gt; "new" } format.xml { render :xml =&gt; @line_item.errors, :status =&gt; :unprocessable_entity } end end end </code></pre> <p><strong>views/bikes/show</strong></p> <pre><code>&lt;%= button_to "Rent this Bicycle!", line_items_path(:bike_id =&gt; @bike), {:id =&gt; "rentthisbike"} %&gt; </code></pre> <p><strong>bike.rb</strong></p> <pre><code>class Bike &lt; ActiveRecord::Base belongs_to :user has_many :line_items attr_accessible :name, :description, :size, :biketype, :price, :photo, :id, :address, :city, :state, :zip, :latitude, :longitude, :neighborhood, :bike_id end </code></pre> <p><strong>line_item.rb</strong></p> <pre><code>class LineItem &lt; ActiveRecord::Base belongs_to :bike belongs_to :cart accepts_nested_attributes_for :bike, :cart attr_accessible :bike_id, :bike, :cart, :name, :description, :size, :biketype, :price, :photo, :id, :address, :city, :state, :zip, :latitude, :longitude, :neighborhood end </code></pre> <p><strong>cart.rb</strong></p> <pre><code>class Cart &lt; ActiveRecord::Base has_many :line_items, :dependent =&gt; :destroy belongs_to :user accepts_nested_attributes_for :line_items attr_accessible :bike_id, :line_items, :name, :description, :size, :biketype, :price, :photo, :id, :address, :city, :state, :zip, :latitude, :longitude, :neighborhood end </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
 

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