param is missing or the value is empty: purchase - ruby-on-rails

I'm trying to pass the following inside a def create method. The create method is in the transactions controller.
#purchases = current_shop.purchases.build(purchase_params)
#purchases.save!
private
def purchase_params
params.require(:purchase).permit(:shop_id, :subscription_id, :created_at)
end
And returns this error:
ActionController::ParameterMissing in TransactionsController#create
param is missing or the value is empty: purchase
Update 1
Logs:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"aJWUUEwgtG0o52MEHSOcNETj1Ueo+4NvLBD+y5LMPHxtHnOEe1Zgs3IMADdv5y+dbl7Ecgr8LMEjIG6sws9kqg==", "payment_method_nonce"=>"bf7458d2-d3a4-02c9-2593-526174f50822"}
Cart Load (0.1ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = ? LIMIT ? [["id", 93], ["LIMIT", 1]]
Shop Load (0.3ms) SELECT "shops".* FROM "shops" WHERE "shops"."id" = ? ORDER BY "shops"."id" ASC LIMIT ? [["id", 13], ["LIMIT", 1]]
LineItem Load (0.4ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = ? [["cart_id", 93]]
Subscription Load (0.1ms) SELECT "subscriptions".* FROM "subscriptions" WHERE "subscriptions"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Completed 400 Bad Request in 2899ms (ActiveRecord: 1.1ms)
ActionController::ParameterMissing (param is missing or the value is empty: purchase):
app/controllers/transactions_controller.rb:60:in purchase_params'
app/controllers/transactions_controller.rb:31:in create'
Update 2
<p id="notice"><%= notice %></p>
<script src="https://js.braintreegateway.com/v2/braintree.js"></script>
<div class="form-container radius-box glassy-bg small-10 small-centered medium-8 large-6 columns">
<h2 class="mbs">New Transaction</h2>
<%= form_tag transactions_path do%>
<p>Please enter your payment details:</p>
<div id="dropin"></div>
<%=submit_tag "Pay #{#cart.total_price}$", class: "button mt1" %>
<%end%>
</div>

Related

Custom Rails Method Not Updating Attribute

I have a custom method to update a join table row that used to work and is for some reason errorlessly-failing.
The app is a basic course portal with courses and lessons joined by lesson_completions, which have user_ids, lesson_ids, and a boolean value for complete.
The link I'm using looks like this:
<% if #lesson_completion.complete %>
<td class="pr-1"><%= link_to "<i class='far fa-check-square'></i>".html_safe, uncomplete_lesson_path(#lesson), method: :post, class: "text-red" %></td>
<td><%= link_to "Mark as Unfinished".html_safe, uncomplete_lesson_path(#lesson), method: :post, class: "text-red" %></td>
<% else %>
<td class="pr-1"><%= link_to "<i class='far fa-square'></i>".html_safe, complete_lesson_path(#lesson), method: :post, class: "text-red" %></td>
<td><%= link_to "Mark Lesson as Completed".html_safe, complete_lesson_path(#lesson), method: :post, class: "text-red" %></td>
<% end %>
The methods are in my lesson_completion_controller:
def complete_lesson
#lesson_completion = LessonCompletion.find(params[:id])
if #lesson_completion.update_attributes(complete: true)
redirect_to course_module_path(CourseModule.find(Lesson.find(#lesson_completion.lesson_id).id))
flash[:notice] = "Congratulations on completing that lesson!"
else
redirect_to lesson_path(Lesson.find(#lesson_completion.lesson_id))
flash[:warning] = "Oops! Something went wrong!"
end
end
def uncomplete_lesson
#lesson_completion = LessonCompletion.find(params[:id])
if #lesson_completion.update_attributes(complete: false)
redirect_to lesson_path(Lesson.find(#lesson_completion.lesson_id))
flash[:notice] = "Congratulations on completing that lesson!"
else
redirect_to lesson_path(Lesson.find(#lesson_completion.lesson_id))
flash[:warning] = "Oops! Something went wrong!"
end
end
If I use a debugger and look at the value for #lesson_completion on that page it confirms the correct user_id and lesson_id values.
My routes look like this:
post "lesson_completion/:id/complete_lesson" => "lesson_completion#complete_lesson", as: "complete_lesson"
post "lesson_completion/:id/uncomplete_lesson" => "lesson_completion#uncomplete_lesson", as: "uncomplete_lesson"
When I click the button, the server log shows no errors:
Started POST "/lesson_completion/1/complete_lesson" for ::1 at 2020-09-17 15:17:37 -0700
Processing by LessonCompletionController#complete_lesson as HTML
Parameters: {"authenticity_token"=>"HlCIdRVnOJZIHwPqWoJcu3XpNppi5LNSFvL4odU7DsR42Mw6Ld60IXJxzO/8yEw0qX/LH2PuWFuaywP4Ci3VRw==", "id"=>"1"}
LessonCompletion Load (0.8ms) SELECT "lesson_completions".* FROM "lesson_completions" WHERE "lesson_completions"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/lesson_completion_controller.rb:4
(0.1ms) BEGIN
↳ app/controllers/lesson_completion_controller.rb:5
Lesson Load (1.2ms) SELECT "lessons".* FROM "lessons" WHERE "lessons"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/lesson_completion_controller.rb:5
User Load (1.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/lesson_completion_controller.rb:5
(0.1ms) COMMIT
↳ app/controllers/lesson_completion_controller.rb:5
CACHE Lesson Load (0.0ms) SELECT "lessons".* FROM "lessons" WHERE "lessons"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/lesson_completion_controller.rb:6
CourseModule Load (0.8ms) SELECT "course_modules".* FROM "course_modules" WHERE "course_modules"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/lesson_completion_controller.rb:6
Redirected to http://localhost:5000/course_modules/1
Completed 302 Found in 19ms (ActiveRecord: 4.3ms)
Can anyone see why this value isn't updating? It used to work and is driving me absolutely bonkers now!

I have a NoMethodError in one of my controllers

Just added a new comment feature to my rails app and stumbled upon this issue. I'm getting a NoMethodError in Pics#show which comes from my _comment.html.haml partial.
I can see the comment thread on my show page but after I post the comment I'm getting this. Can go back to uncommented pics, but can't go to the ones I've already commented on.
I've been staring at the code for a while now and I need a fresh pair of eyes.
Started GET "/pics/14" for 127.0.0.1 at 2018-12-19 23:44:51 +0000
(0.5ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
↳ /Users/alexfurtuna/.rvm/gems/ruby-2.4.0/gems/activerecord-5.2.2/lib/active_record/log_subscriber.rb:98
Processing by PicsController#show as HTML
Parameters: {"id"=>"14"}
Pic Load (0.4ms) SELECT "pics".* FROM "pics" WHERE "pics"."id" = $1 LIMIT $2 [["id", 14], ["LIMIT", 1]]
↳ app/controllers/pics_controller.rb:53
CACHE Pic Load (0.0ms) SELECT "pics".* FROM "pics" WHERE "pics"."id" = $1 LIMIT $2 [["id", 14], ["LIMIT", 1]]
↳ app/controllers/pics_controller.rb:9
Rendering pics/show.html.haml within layouts/application
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/views/pics/show.html.haml:14
(0.7ms) SELECT COUNT(*) FROM "votes" WHERE "votes"."votable_id" = $1 AND "votes"."votable_type" = $2 AND "votes"."vote_flag" = $3 [["votable_id", 14], ["votable_type", "Pic"], ["vote_flag", true]]
↳ app/views/pics/show.html.haml:20
Comment Load (0.5ms) SELECT "comments".* FROM "comments" WHERE "comments"."commentable_id" = $1 AND "comments"."commentable_type" = $2 [["commentable_id", 14], ["commentable_type", "Pic"]]
↳ app/views/pics/show.html.haml:28
Rendered collection of comments/_comment.html.haml [1 times] (153.0ms)
Rendered pics/show.html.haml within layouts/application (220.1ms)
Completed 500 Internal Server Error in 267ms (ActiveRecord: 13.0ms)
ActionView::Template::Error (undefined method `comment_comments_path' for #<#. <Class:0x007fa535ee08b8>:0x007fa535ee9d50>
Did you mean? pic_comment_comments_path):
2: = comment.body
3: %small
4: Submitted #{time_ago_in_words(comment.created_at)} ago
5: = form_for [comment, Comment.new] do |f|
6: = f.text_area :body, placeholder: "Add a Reply"
7: %br/
8: = f.submit "Reply"
app/views/comments/_comment.html.haml:5:in `_app_views_comments__comment_html_haml___2866288612795974586_70173756400620'
app/views/pics/show.html.haml:28:in `_app_views_pics_show_html_haml___2738689311384334047_70173775563600'
And this is my _comment partial.
%li
= comment.body
%small
Submitted #{time_ago_in_words(comment.created_at)} ago
= form_for [comment, Comment.new] do |f|
= f.text_area :body, placeholder: "Add a Reply"
%br/
= f.submit "Reply"
%ul
= render partial: 'comments/comment', collection: comment.comments
Everything is fixed now and working properly. Had to pass the #pic variable. Thanks

Rails 5 Enum With Select Field Not Saving

I understand that this has been asked many times, but for some reason none of the other solutions worked for me. I'm still unable to save a field with an enum on update.When I pass a non-enum value, like first_name, with the same form, it updates just fine, but the enum value, gender, never saves even though it shows that it is...
View:
<%= form_for(#patient, url: patient_path(params[:id])) do |f| %>
<%= f.fields_for :role do |r| %>
<%= r.fields_for :user do |u| %>
<div class="keyvalue">
<div class="key"><p>Gender</p></div>
<div class="value">
<%= u.select :gender, User.genders.map { |key, value| [key.humanize, key] }, include_blank: '-Select A Gender-' %>
</div>
<div class="push"></div>
</div><!--keyvalue-->
<% end %>
<% end %>
<% end %>
Controller:
def update
#patient = Patient.find(params[:id])
if #patient.update(patient_params)
flash[:success] = "Patient's record has been updated."
redirect_to patient_path(params[:id])
else
flash[:error] = #patient.errors.full_messages.to_sentence
redirect_to patient_path(params[:id])
end
end
Log:
Parameters: {"utf8"=>"✓", "authenticity_token"=>"*********", "commit"=>"Update", "patient"=>{"role_attributes"=>{"user_attributes"=>{"first_name"=>"John", "middle_name"=>"Joseph", "last_name"=>"Doe", "date_of_birth"=>"1943-12-25", "gender"=>"male", "blood_type"=>"", "ethnicity"=>"", "marital_status"=>"", "id"=>"1"}, "id"=>"1"}}, "id"=>"1"}
Patient Load (0.1ms) SELECT "patients".* FROM "patients" WHERE "patients"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
(0.0ms) begin transaction
Role Load (0.1ms) SELECT "roles".* FROM "roles" WHERE "roles"."roleable_id" = ? AND "roles"."roleable_type" = ? LIMIT ? [["roleable_id", 1], ["roleable_type", "Patient"], ["LIMIT", 1]]
User Load (0.1ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT ? [["id", 1], ["LIMIT", 1]]
User Exists (0.1ms) SELECT 1 AS one FROM "users" WHERE "users"."username" = ? AND ("users"."id" != ?) LIMIT ? [["username", "dev"], ["id", 1], ["LIMIT", 1]]
SQL (0.3ms) UPDATE "users" SET "gender" = ?, "updated_at" = ? WHERE "users"."id" = ? [["gender", 0], ["updated_at", "2018-04-24 02:11:23.126843"], ["id", 1]]
(2.6ms) commit transaction
Redirected to http://localhost:3000/patients/1
Completed 302 Found in 10ms (ActiveRecord: 3.2ms)
Enum in User model:
enum gender: [:male, :female, :non_binary, :rather_not_say]
Migration:
t.integer :gender
The log shows no issue, it shows the gender field being updated, but if I go to the rails console it shows gender as nil

Couldn't find Bonus with 'id'= , while in rails console everything works fine

My params hash looks like this: Parameters: {"id"=>"6", "bonus_id"=>"2", "bonus_title"=>"deposit-match-row"}, and this is my controller:
def load_more_bonuses
#more_casinos = []
#bonus_title = params[:bonus_title]
bonus = Bonus.find(params[:bonus_id])
#more_casinos << bonus.casinos.where('casinos.id >?', params[:id]).order(id: :asc).limit(6).uniq
respond_to do |format|
format.js
end
end
I get the following error: ActiveRecord::RecordNotFound (Couldn't find Bonus with 'id'=) In rails console everything works fine, doing: bonus = Bonus.find(2) gives me my bonus record. What's wrong with the code above, what can be done to get rid of the error? Thanks.
EDIT
Full server log:
Started GET "/load_more_bonuses?id=6&bonus_id=2&bonus_title=deposit-match-row" for 127.0.0.1 at 2017-04-24 12:08:00 +0300
Processing by BonusesController#load_more_bonuses as JS
Parameters: {"id"=>"6", "bonus_id"=>"2", "bonus_title"=>"deposit-match-row"}
Started GET "/load_more_bonuses" for 127.0.0.1 at 2017-04-24 12:08:00 +0300
Processing by BonusesController#load_more_bonuses as JS
Casino Load (7.2ms) SELECT "casinos".* FROM "casinos" WHERE "casinos"."casino_of_the_month" = $1 LIMIT $2 [["casino_of_the_month", true], ["LIMIT", 1]]
Casino Load (1.4ms) SELECT "casinos".* FROM "casinos" WHERE "casinos"."casino_of_the_month" = $1 LIMIT $2 [["casino_of_the_month", true], ["LIMIT", 1]]
Bonus Load (1.2ms) SELECT "bonuses".* FROM "bonuses" WHERE "bonuses"."id" = $1 LIMIT $2 [["id", 2], ["LIMIT", 1]]
Bonus Load (15.7ms) SELECT "bonuses".* FROM "bonuses" WHERE "bonuses"."id" = $1 LIMIT $2 [["id", nil], ["LIMIT", 1]]
Rendering bonuses/load_more_bonuses.js.erb
Completed 404 Not Found in 27ms (ActiveRecord: 17.1ms)
ActiveRecord::RecordNotFound (Couldn't find Bonus with 'id'=):
Casino Load (2.2ms) SELECT DISTINCT "casinos".* FROM "casinos" INNER JOIN "casino_bonuses" ON "casinos"."id" = "casino_bonuses"."casino_id" WHERE "casino_bonuses"."bonus_id" = $1 AND (casinos.id >'6') ORDER BY "casinos"."id" ASC LIMIT $2 [["bonus_id", 2], ["LIMIT", 6]]
app/controllers/bonuses_controller.rb:75:in `load_more_bonuses'
Rendering /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb
Rendering /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.text.erb
Rendered /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.text.erb (0.7ms)
Rendering /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb
Rendered /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.text.erb (0.8ms)
Rendering /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb
Rendered /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.text.erb (1.2ms)
Rendered /home/spacechick/.rvm/gems/ruby-2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.text.erb (26.8ms)
(0.5ms) SELECT COUNT(*) FROM "ratings" WHERE "ratings"."casino_id" = $1 [["casino_id", 10]]
(0.4ms) SELECT SUM("ratings"."score") FROM "ratings" WHERE "ratings"."casino_id" = $1 [["casino_id", 10]]
CACHE (0.0ms) SELECT COUNT(*) FROM "ratings" WHERE "ratings"."casino_id" = $1 [["casino_id", 10]]
CACHE (0.0ms) SELECT COUNT(*) FROM "ratings" WHERE "ratings"."casino_id" = $1 [["casino_id", 10]]
CACHE (0.0ms) SELECT SUM("ratings"."score") FROM "ratings" WHERE "ratings"."casino_id" = $1 [["casino_id", 10]]
CACHE (0.0ms) SELECT COUNT(*) FROM "ratings" WHERE "ratings"."casino_id" = $1 [["casino_id", 10]]
Rendered bonuses/_load_more_casinos_list.html.erb (150.9ms)
Rendered bonuses/load_more_bonuses.js.erb (154.1ms)
Completed 200 OK in 193ms (Views: 159.7ms | ActiveRecord: 11.5ms)
EDIT 2
_load_more_casinos_list.html.erb:
<% #more_casinos.flatten.uniq.sort_by{ |id| id[:id] }.reverse!.take(6).each do |casino| %>
<div class="col-lg-4 col-md-6 col-sm-12 col-xs-12">
<div class="bonus-casino-index-item" data-id="<%= casino.id %>">
<div class="bonus-casinos-index-item-flip">
<div class="front">
<div class="bonus-casino-background" style="background-color: <%= casino.background_color %>">
<div class="bonus-info-sign">
<span class="glyphicon glyphicon-info-sign"></span>
</div>
<% if casino.new === true %>
<div class="bonus-casino-new"></div>
<% elsif casino.hot === true %>
<div class="bonus-casino-hot"></div>
<% elsif casino.exclusive === true %>
<div class="bonus-casino-exclusive"></div>
<% end %>
<div class="bonus-casino-logo">Logo will be here</div>
<div class="bonus-casino-rating">
<div class="rateit" data-rateit-value="<%= casino.average_rating %>" data-rateit-ispreset="true" data-rateit-readonly="true" data-rateit-mode="font" style="font-size:20px"></div>
</div>
<div class="bonus-casino-bonus-info">
<%= casino.bonus_info %>
</div>
</div>
</div>
<div class="back">
<div class="bonus-casino-background-back">
<div class="bonus-casino-back-close">
<span class="glyphicon glyphicon-remove-sign"></span>
</div>
<p class="bonus-casino-bonus-info-back"><%= casino.bonus_info.truncate(50) %></p>
<p class="bonus-casino-average-rating">Score: <%= casino.average_rating.round(2) %></p>
<div class="bonus-casino-bonus-description"><%= strip_tags(casino.description).truncate(120) %></div>
</div>
</div>
</div>
<div class="bonuses-page-casino-list-links">
<%= link_to 'Review', casino, class: 'bonus-casino-index-item-review' %>
<%= link_to 'Join now', '#', class: 'bonus-casino-index-item-join-now' %>
</div>
</div>
</div>
<% end %>
EDIT 3
puts #more_casinos gives me:
Casino Load (4.1ms) SELECT "casinos".* FROM "casinos" WHERE "casinos"."casino_of_the_month" = $1 LIMIT $2 [["casino_of_the_month", true], ["LIMIT", 1]]
Casino Load (1.8ms) SELECT DISTINCT "casinos".* FROM "casinos" INNER JOIN "casino_bonuses" ON "casinos"."id" = "casino_bonuses"."casino_id" WHERE "casino_bonuses"."bonus_id" = $1 AND (casinos.id >'6') ORDER BY "casinos"."id" ASC LIMIT $2 [["bonus_id", 2], ["LIMIT", 6]]
Bonus Load (0.4ms) SELECT "bonuses".* FROM "bonuses" WHERE "bonuses"."id" = $1 LIMIT $2 [["id", nil], ["LIMIT", 1]]
#<Casino:0x000000082c8820>
And load_more_bonuses.js.erb:
<% if #more_casinos.any? %>
$('#<%= #bonus_title.parameterize %>-row').append('<%= j render 'bonuses/load_more_casinos_list' %>');
<% end %>
EDIT 4
Ajax call in application.js
$('.bonus-casinos-load-more').click(function () {
var lastId = $(this).parent().parent().parent().children('.first-row').children().last().children().attr('data-id');
var bonusId = $(this).attr('data-id');
var bonusTitle = $(this).parent().parent().parent().children('.first-row').attr('id');
$.ajax({
type: 'GET',
url: $(this).attr('href'),
data: {
id: lastId,
bonus_id: bonusId,
bonus_title: bonusTitle
},
dataType: 'script'
});
});
The problem should be related to the view, because in your log, it sends 2 requests.
One requests with legal querystring, 1 request querystring is empty.
Started GET "/load_more_bonuses?id=6&bonus_id=2&bonus_title=deposit-match-row" for 127.0.0.1 at 2017-04-24 12:08:00 +0300
Processing by BonusesController#load_more_bonuses as JS
Parameters: {"id"=>"6", "bonus_id"=>"2", "bonus_title"=>"deposit-match-row"}
Started GET "/load_more_bonuses" for 127.0.0.1 at 2017-04-24 12:08:00 +0300
In your view file, it will sent another request, but without paramters.
It's send by the ajax call, then check the parameters, find out why it's empty. Add some console.log at the js code.

loop iterates over all items, for each item

I'm running into an issue where I rander a partial using AJAX and for some reason the line_items renders to the amount of products in it. So if there's 2 products, it loops through all line_items 2 times, causing it to be 4 elements listed instead of 2. So the loop keeps going by the amount of products in the line_items.
In my create.js.erb I have:
$('#shopping-cart').html("<%= escape_javascript render(#cart) %>");
and my _cart:
<div id="shopping-cart">
<div id="shopping-cart-header">
</div>
<div id="shopping-cart-items">
<table>
<%= render cart.line_items %>
<tr class="total-line">
<td colspan="2">Total</td>
<td class="total-cell"><%= number_to_currency(cart.total_price, unit: '') %></td>
</tr>
</table>
<%= button_to 'Empty cart', cart, method: :delete %>
</div>
<div id="shopping-cart-footer">
<%= link_to 'New order', new_order_path, class: 'btn btn-main btn-lg', data: { no_turbolink: true } %>
</div>
</div>
and the issues is with render cart.line_items I guess:
<% #cart.line_items.each do |item| %>
<% if line_item == #current_item %>
<tr id="current-item">
<% else %>
<tr>
<% end %>
<td><%= item.quantity %> ×</td>
<td>
<p><%= item.product.name %></p>
<% if item.line_item_attributes.exists? %>
<% item.line_item_attributes.each do |attribute| %>
<i><%= attribute.product_attribute.name %></i>
<% end %>
<% end %>
</td>
<td class="item-price"><%= number_to_currency(item.total_price, unit: '') %></td>
</tr>
<% end %>
if I've now added 2 products they're shown twice like this:
1 × red shirt 490.00
1 × blue shirt 89.00
1 × red shirt 490.00
1 × blue shirt 89.00
Total 579.00
Any one know what's going on? My logs are:
Started POST "/line_items" for ::1 at 2016-01-25 08:53:41 +0100
Processing by LineItemsController#create as JS
Parameters: {"utf8"=>"✓", "line_item"=>{"product_id"=>"5", "instruction"=>""}, "commit"=>"Legg til"}
Cart Load (0.4ms) SELECT "carts".* FROM "carts" WHERE "carts"."id" = $1 LIMIT $2 [["id", 92], ["LIMIT", 1]]
Product Load (0.3ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
(0.3ms) SELECT COUNT(*) FROM "line_items" WHERE "line_items"."cart_id" = $1 AND "line_items"."product_id" = $2 [["cart_id", 92], ["product_id", 5]]
LineItem Load (0.4ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = $1 AND "line_items"."product_id" = $2 [["cart_id", 92], ["product_id", 5]]
LineItemAttribute Load (0.4ms) SELECT "line_item_attributes".* FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 [["line_item_id", 132]]
LineItem Load (0.4ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = $1 AND "line_items"."id" = $2 LIMIT $3 [["cart_id", 92], ["id", 132], ["LIMIT", 1]]
(0.2ms) BEGIN
Product Load (0.4ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
SQL (11.6ms) UPDATE "line_items" SET "quantity" = $1, "updated_at" = $2 WHERE "line_items"."id" = $3 [["quantity", 2], ["updated_at", 2016-01-25 07:53:41 UTC], ["id", 132]]
(0.8ms) COMMIT
LineItem Exists (1.0ms) SELECT 1 AS one FROM "line_items" WHERE "line_items"."cart_id" = $1 LIMIT $2 [["cart_id", 92], ["LIMIT", 1]]
LineItem Load (0.7ms) SELECT "line_items".* FROM "line_items" WHERE "line_items"."cart_id" = $1 [["cart_id", 92]]
Product Load (0.5ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
LineItemAttribute Exists (0.4ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 131], ["LIMIT", 1]]
LineItemAttribute Exists (1.0ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 131], ["LIMIT", 1]]
Product Load (0.4ms) SELECT "products".* FROM "products" WHERE "products"."id" = $1 LIMIT $2 [["id", 5], ["LIMIT", 1]]
LineItemAttribute Exists (0.4ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 132], ["LIMIT", 1]]
LineItemAttribute Exists (0.3ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 132], ["LIMIT", 1]]
LineItemAttribute Exists (0.4ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 131], ["LIMIT", 1]]
LineItemAttribute Exists (0.3ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 131], ["LIMIT", 1]]
LineItemAttribute Exists (0.3ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 132], ["LIMIT", 1]]
LineItemAttribute Exists (0.3ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 132], ["LIMIT", 1]]
Rendered line_items/_line_item.html.erb (22.9ms)
LineItemAttribute Exists (0.5ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 131], ["LIMIT", 1]]
LineItemAttribute Exists (0.4ms) SELECT 1 AS one FROM "line_item_attributes" WHERE "line_item_attributes"."line_item_id" = $1 LIMIT $2 [["line_item_id", 132], ["LIMIT", 1]]
Rendered carts/_cart.html.erb (74.4ms)
Rendered line_items/create.js.erb (78.1ms)
It seems that _line_items are rendered, and then _cart (which again contains line_items) are rendered - maybe thats an issue?
You're correct. When you call render cart.line_items, you're rendering a collection. To quote the Rails documentation,
When you pass a collection to a partial via the :collection option, the partial will be inserted once for each member in the collection:
<h1>Products</h1>
<%= render partial: "product", collection: #products %>
(this is the same as your render cart.line_items)
And then in the partial you will have access to a product (or line_item in your case) local variable, like this:
<p>Product Name: <%= product.name %></p>
So: Rewrite your partial view to represent a single line_item with a corresponding line_item variable instead of a collection.

Resources