Ruby on Rails Tuesday, November 24, 2015

> On Saturday, November 21, 2015 at 4:44:02 PM UTC-5, Colin Law wrote:
>>
>> On 21 November 2015 at 18:50, fugee ohu <fuge...@gmail.com <javascript:>>
>> wrote:
>>
>>> i'm trying to follow these instructions:
>>>
>>> in my categories_controller.rb
>>> def index @parent_categories = Category.without_parents
>>>
>>> in my index.html.erb
>>> <ul> <%= render @parent_categories %> </ul>
>>> in my _categories.html.erb
>>> <ul> <li> <strong><%= category.name %></strong> <ul> <%= render
>>> category.categories %> </ul> </li> </ul>
>>> but this doesn't work i get unknown method wihtout_parents and couldn't
>>> figure out what without_parents was supposed to be so, i tried changing the
>>> line in the controller to @parent_categories =
>>> Category.where("parent_id=0") and it was on to the next error, now i get
>>> undefined method `categories' for #<Category:0xb1604e2c> My understanding
>>> is that in the statement, category is the partial view and categories means
>>> the entire collection, so then why doesn't rails recognize the meaning of
>>> categories as the entire collection and what's the story with
>>> "without_parents" ? ~ thanks, fugee
>>>
>>
>>
>> I am afraid your ideas are so horribly mixed up it is difficult to know
>> where to start. I think the instructions you are following must be rather
>> poor. I suggest instead you start by working right through
>> railstutorial.org (which is free to use online) which will show you the
>> basics of Rails in a way which most can follow.
>>
>> Colin
>>
>>
>>

Cutting this from the top of the message and putting it at the bottom:

fugee ohu <fugee279@gmail.com> writes:

> after defining wihtout_parent in the model i reloaded the page and got this
> error for line 2 of index.html.erb
>
> <%= render @parent_categories %>
> error:
>
> 'nil' is not an ActiveModel-compatible object. It must implement :to_partial_path.
>
> was <%= render @parent_categories %> supposed to call the
> _category.html.erb partial ?

What's the content of @parent_categories at that point?
Insert `<%= debug @parent_categories %>` above the render line and see
what the view sees.

I wrote a small test app to deal with self-nested objects, so I know
this sort of thing does work. As we only get to see what you show us,
perhaps you could give us a link to your public repository. Or even put
up a gist with all the applicable parts.

Or do what I did and write a tiny example application focusing just on
just this part and see if you can get it to work, and provide a link to
the app's source for us to see.

--
Tamara Temple
tamouse@gmail.com
http://www.tamouse.org

--
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/m2lh9mmyew.fsf%40gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment