I have a NoMethodError in one of my controllers - ruby-on-rails

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

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!

user.update rollback error in model method

As everything working as expected, i'm trying to save the new values in the database but i'm getting a rollback error on update
my model.rb
class User < ApplicationRecord
before_update :update_password
def self.update_password(username, new_password, new_password_conf, old_password)
user = find_by_username(username)
if new_password == new_password_conf && BCrypt::Engine.hash_secret(old_password, user.salt) == user.encrypted_password
new_salt = BCrypt::Engine.generate_salt
new_pass = BCrypt::Engine.hash_secret(new_password, new_salt)
user.update(encrypted_password: new_pass, salt: new_salt)
else
puts "Something went Wrong"
end
end
end
my users_controller.rb
def change_password
user = User.update_password( User.find(session[:user_id]).username,params[:password],params[:password_confirmation],params[:old_password])
end
my html.erb
<%= form_for(:user, :url => {:controller => 'users', :action => 'change_password'}) do |f| %>
<center><p> Παλιός Κωδικός Πρόσβασης</br> <%= f.password_field :old_password, placeholder: "Παλιός Κωδικός Πρόσβασης", name: "old_password"%> </p></center>
<center><p> Νέος Κωδικός Πρόσβασης</br> <%= f.password_field :password, placeholder: "Νέος Κωδικός Πρόσβασης", name: "password"%></p></center>
<center><p> Επιβεβαίωση Νέου Κ.Πρόσβασης</br> <%= f.password_field :password_confirmation, placeholder: "Επιβεβαίωση Νέου Κ.Πρόσβασης", name: "password_confirmation" %></p></center>
<center><%= f.submit "Αποθήκευση", class: 'log_in_button' %><center>
<% end %>
Console output
Started POST "/users/change_password" for 127.0.0.1 at 2020-08-10 01:13:18 +0300
Processing by UsersController#change_password as HTML
Parameters: {"authenticity_token"=>"ORVdeLRZYMjP7XIMqligykYH7YqnjzprTpQnCl3G9XPj36hgEEcC+C/Y1F6Tp3QTOVrheaYD/SZM0BX+i3YERQ==", "old_password"=>"[FILTERED]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "commit"=>"Αποθήκευση"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
↳ app/controllers/users_controller.rb:76:in `change_password'
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."username" = $1 LIMIT $2 [["username", "mauras"], ["LIMIT", 1]]
↳ app/models/user.rb:36:in `update_password'
(0.2ms) BEGIN
↳ app/models/user.rb:41:in `update_password'
User Exists? (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."username" = $1 AND "users"."id" != $2 LIMIT $3 [["username", "mauras"], ["id", 1], ["LIMIT", 1]]
↳ app/models/user.rb:41:in `update_password'
User Exists? (0.4ms) SELECT 1 AS one FROM "users" WHERE "users"."email" = $1 AND "users"."id" != $2 LIMIT $3 [["email", "asdas#adasd.com"], ["id", 1], ["LIMIT", 1]]
↳ app/models/user.rb:41:in `update_password'
(0.3ms) ROLLBACK
↳ app/models/user.rb:41:in `update_password'
Rendering users/change_password.html.erb within layouts/application
Rendered users/change_password.html.erb within layouts/application (Duration: 0.8ms | Allocations: 365)
[Webpacker] Everything's up-to-date. Nothing to do
Completed 200 OK in 608ms (Views: 6.3ms | ActiveRecord: 2.1ms | Allocations: 10770)
also try user.save still nothing,

Unending/non-terminating database query - Rails

I want to implement a way of clicking a button and running a method without having to switch to the view of the specifid item/object found by id. I'm using PostgrSQL.
In my PaymentsController I have a method called withdraw, which looks something like this:
def withdraw
#payment = Payment.find(params[:id])
#payment.withdrawn = true
#payment.amount_interest = withdraw.amount * 1.1
#payment.save
head :ok
end
And the route:
patch '/withdraw/:id', to: 'payments#withdraw', as: :withdraw
each statement with link_to:
<% #payments.each do |withdraw| %>
<tr>
<td><%= withdraw.amount %></td>
<td><%= link_to 'Withdraw', withdraw_path(withdraw), method: :patch, remote: true %></td>
</tr>
<% end %>
EDIT: Upon clicking "Withdraw" I get an unending database query that looks like this:
Started PATCH "/withdraw/1" for 127.0.0.1 at 2016-11-11 21:20:34 +0200
Processing by PaymentsController#withdraw as JS
Parameters: {"id"=>"1"}
Started PATCH "/withdraw/1" for 127.0.0.1 at 2016-11-11 21:20:34 +0200
Processing by PaymentsController#withdraw as JS
Member Load (40.0ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 ORDER BY "members"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Parameters: {"id"=>"1"}
Member Load (1.4ms) SELECT "members".* FROM "members" WHERE "members"."id" = $1 ORDER BY "members"."id" ASC LIMIT $2 [["id", 1], ["LIMIT", 1]]
Payment Load (0.0ms) SELECT "payments".* FROM "payments" WHERE "payments"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Payment Load (2.0ms) SELECT "payments".* FROM "payments" WHERE "payments"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Payment Load (1.1ms) SELECT "payments".* FROM "payments" WHERE "payments"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
Payment Load (0.0ms) SELECT "payments".* FROM "payments" WHERE "payments"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]]
My Payments model has the following:
account:string amount:decimal paid:boolean withdrawn:boolean amount_interest:decimal
belongs_to :member
Any assistance will be greatly appreciated.
The issue was a bug in my withdraw method.
changed:
#payment.amount_interest = withdraw.amount * 1.1
to:
#payment.amount_interest = #payment.amount * 1.1

Rails - Name can't be blank error when the input isn't blank

I get an error of 'Name can't be blank' and "Name only allows letters, numbers and '-'" when trying to update a name. This was working fine but I have just gone through it again while writing a test for it and realise it isn't working anymore, I can't figure out why or what has changed to break it.
Categories controller
def update
if #category.update category_params
redirect_to new_guide_category_item_path(#guide, #category)
flash[:info] = "Updated successfully"
else
render 'edit'
end
end
private
def category_params
params.require(:category).permit(:name, :template)
end
edit.html.erb
<%= render 'shared/error_messages', object: f.object %>
.....
<%= form_for([#guide, #category], url: guide_category_path) do |f| %>
<%= f.label :name, "Category name" %>
<%= f.text_field :name %>
<%= f.label :template, "Template" %>
<%= f.text_area :template, { :id => 'edit' } %>
<%= f.submit "Save", :value => "Save Template" %>
<% end %>
model
validates :name, presence: true, length: { maximum: 255 }, uniqueness: { scope: :guide_id, case_sensitive: false },
exclusion: { in: %w( guide guides category categories item items page pages post posts tag tags key keys item key item keys item-key item-keys item_key item_keys mod moderator mods moderators admin admins), message: "%{value} cant be taken." },
format: { with: /\A[a-zA-Z0-9 -]+\z/, message: "only allows letters, numbers, spaces and '-'" }
routes
resources :guides do
resources :categories, only: [:new, :create, :edit, :update] do
end
end
Anyone have an idea of what might be going wrong?
Edit added log output
Started PATCH "/guides/ghj/categories/ijijij" for ::1 at 2016-02-11 14:08:04 +1100
Processing by CategoriesController#update as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"IqiUJ8wF8ZY4t8f91+t4aOMc9xenx/F2beKjKs9GY7JzLD6ZgPYDY1ueC2s+OIDL+PjROVtMe2+GvgYdan1CDQ==", "category"=>{"name"=>"ijijijddd", "template"=>""}, "commit"=>"Save Template", "guide_id"=>"ghj", "id"=>"ijijij"}
[1m[35mUser Load (0.2ms)[0m SELECT "users".* FROM "users" WHERE "users"."id" = ? LIMIT 1 [["id", 1]]
[1m[36mGuide Load (0.1ms)[0m [1mSELECT "guides".* FROM "guides" WHERE "guides"."slug" = ? ORDER BY "guides"."id" ASC LIMIT 1[0m [["slug", "ghj"]]
[1m[35mCategory Load (0.1ms)[0m SELECT "categories".* FROM "categories" WHERE "categories"."slug" = ? ORDER BY "categories"."id" ASC LIMIT 1 [["slug", "ijijij"]]
[1m[36m (0.1ms)[0m [1mSELECT "category_item_keys"."name" FROM "category_item_keys" WHERE "category_item_keys"."category_id" = ?[0m [["category_id", 6]]
[1m[35m (0.0ms)[0m SELECT "check_category_item_keys"."name" FROM "check_category_item_keys" WHERE "check_category_item_keys"."category_id" = ? [["category_id", 6]]
[1m[36m (0.1ms)[0m [1mSELECT "category_item_keys"."name" FROM "category_item_keys" WHERE "category_item_keys"."category_id" = ? AND "category_item_keys"."key_type" = ?[0m [["category_id", 6], ["key_type", 1]]
[1m[35m (0.0ms)[0m SELECT "category_item_keys"."name" FROM "category_item_keys" WHERE "category_item_keys"."category_id" = ? AND "category_item_keys"."key_type" = ? [["category_id", 6], ["key_type", 2]]
[1m[36m (0.1ms)[0m [1mSELECT "category_item_keys"."name" FROM "category_item_keys" WHERE "category_item_keys"."category_id" = ? AND "category_item_keys"."key_type" = ?[0m [["category_id", 6], ["key_type", 3]]
[1m[35mGameModsRelationship Exists (0.1ms)[0m SELECT 1 AS one FROM "game_mods_relationships" WHERE "game_mods_relationships"."user_id" = ? AND "game_mods_relationships"."category_id" = 3 LIMIT 1 [["user_id", 1]]
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
[1m[35mCategoryItemKey Exists (0.1ms)[0m SELECT 1 AS one FROM "category_item_keys" WHERE ("category_item_keys"."name" IS NULL AND "category_item_keys"."guide_id" IS NULL) LIMIT 1
[1m[36mCategory Exists (0.1ms)[0m [1mSELECT 1 AS one FROM "categories" WHERE (LOWER("categories"."name") = LOWER('ijijijddd') AND "categories"."id" != 6 AND "categories"."guide_id" = 3) LIMIT 1[0m
[1m[35m (0.0ms)[0m rollback transaction
[1m[36mCACHE (0.0ms)[0m [1mSELECT 1 AS one FROM "game_mods_relationships" WHERE "game_mods_relationships"."user_id" = ? AND "game_mods_relationships"."category_id" = 3 LIMIT 1[0m [["user_id", 1]]
Rendered shared/_error_messages.html.erb (0.5ms)
Rendered categories/edit.html.erb within layouts/application (5.6ms)
Rendered layouts/_shim.html.erb (0.1ms)
Rendered layouts/_header.html.erb (0.7ms)
Rendered layouts/_footer.html.erb (0.1ms)
Completed 200 OK in 157ms (Views: 145.1ms | ActiveRecord: 1.1ms)`
You need to add error_messages helper tag in the partial. That handles all error messages and show it properly.
It looks like your database has an existing record with the same name. Try inputting a unique name in. In your model, it is checking for :uniqueness.

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