On 25 November 2015 at 22:00, fugee ohu <fugee279@gmail.com> wrote:
> catalog.html.erb fails to display the listings
>
> In catalog.html.erb
> <div>
> <table>
> <% @category.descendants.each do |category| %>
> <% category.listings.each do |listing| %>
> <%= listing.title %>
> <% end %>
> <% end %>
> </table>
> </div>
If my suggestion in the other thread does not help then you can debug
this by using the logger. You could make the above look like
<table>
<% logger.info "descendants count = #{@category.descendants.count}" %>
<% @category.descendants.each do |category| %>
<% logger.info "listings count = #{category.listings.count}" %>
<% category.listings.each do |listing| %>
<% logger.info listing.inspect %>
<%= listing.title %>
Then you can look in the log to get an idea of what is happening.
Perhaps the category has no descendants or they have no listings.
See below also
>
> In my routes.rb
> get '/store/catalog/:id' => 'store#catalog'
>
> In my store_controller.rb
> def catalog
> @category=Category.find(params[:id])
> end
>
> In category.rb
> class Category < ActiveRecord::Base
> acts_as_nested_set
> has_many :listings
> end
>
> In listing.rb
> class Listing < ActiveRecord::Base
> belongs_to :categories
That should be category not categories, though I am surprised that did
not give an error. I hope you are copy/pasting here not re-typing.
Colin
--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLt-BVOSNPZit%3D-2P7_xnRNCdvyUbyXWSkT6kH5B2Yrufg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment