Reputation: 1203
Using Rails 4.0.0 & ruby 2.0.0p247
I've listed all the items in a database plenty of times in Rails. I'm kind of perplexed with what is happening in this instance. I'm simply trying to list all of the "Gears" that a user owns. So I have a specific action in my controller:
def launch_index
@gear = current_user.gears.paginate(page: params[:page], :per_page => 10)
end
Nothing weird just trying to list all of the gears the belong_to a User. In the view this is my code:
<table class="store_gear_list table table-bordered table-striped">
<thead>
<tr>
<th>Gear</th>
<th>Title</th>
<th>Price <span style="font-size: 50%;">( Per Day)</span></th>
<th>Size</th>
<th>Edit/Delete</th>
</tr>
</thead>
<%= @gear.each do |gear| %>
<tr>
<td><%= image_tag gear.image_url(:thumb), :class => "thumbnail_gear_store" %>
</td>
<td><%= gear.title %></td>
<td>$<%= gear.price %></td>
<td><%= gear.size %></td>
<td><ul>
<li style="float:left; padding-left: 3px;"><%= link_to 'Delete', gear_path(gear), confirm: 'Are you sure?', method: :delete, :class => 'btn btn-mini btn-danger' %></li>
</ul></td>
</tr>
<% end %>
</table></br>
<%= will_paginate @gear, class: 'flickr_pagination' %>
The output is normal, meaning I can see each Gear along with the title, prices, size, etc. except one thing. I'm am getting an array above the table that lists every field of each Gear object in a weird array and if there are no Gears I just see empty brackets for the array"[]". I have no idea why that is happening. Any help would be appreciated, thanks.
Here is literally what the view looks like above the table:
[#<Gear id: 391, user_id: 116, title: "Snowboard", size: "152", created_at: "2013-09-15 16:14:15", updated_at: "2013-09-15 16:14:15", price: 89, sub_category_id: 15, image: "7b1feb6ab49fd5d5f16531c7783aab7f.jpg", category_id: nil, remote_image_url: nil, image_a: nil, color: "", year: 2013, latefee: nil, cancellation: nil, minrental: nil, policy: nil, about: nil, address: ""555 Street, city: "city", state: "NY", zip: "78990", latitude: nil, longitude: nil, gmaps: true, country: nil, image_b: nil, image_c: nil, image_d: nil, image_e: nil, image_f: nil, image_g: nil, image_h: nil, image_i: nil>]
What is going on here?
Upvotes: 0
Views: 1311
Reputation: 4193
I suggest that you use - @gear.each
instead of = @gear.each
.
I also strongly suggest that you use plural for variables when you are dealing with "lists" of elements. So rewrite it into:
- @gears.each
Upvotes: 3
Reputation: 10997
the problem is in this line:
<%= @gear.each do |gear| %>
it should be
<% @gear.each do |gear| %>
the <%=
syntax shows whatever is being processed/compiled whereas the <%
syntax does the processing/compiling without showing the results
Upvotes: 3