Hi
I need to do options for categories in view
in controller i have action
def new_to_do
@categories = Category.find(:all)
end
new_to_do template contains
<td><b>Category: </b></td>
<td><select id="item_category_id"
name="item[category_id]">
<%=options_from_collection_for_select @categories, "id",
"category",
@item.category_id %>
</select>
I get error : You have a nil object when you didn''t expect it!
The error occurred while evaluating nil.category_id
So i have 3 tables categories, items, notes
Items belongs to category and note, so I have add those to the model
of item. Do i have to add category model has_many Items call also?
I appreciate that if sombody could help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
> I get error : You have a nil object when you didn''t expect it! > The error occurred while evaluating nil.category_id >You use @item.category_id here without assigning anything to @item, so it''s nil> So i have 3 tables categories, items, notes > Items belongs to category and note, so I have add those to the model > of item. Do i have to add category model has_many Items call also? >Yes, Category needs a has_many :items if Items defined belongs_to :category Shouldn''t note belong_to Item instead the other way around? I just assume this from the name, you may know better. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Yeah. Note belongs to item. Thanks for replay, i have to tried it tomorrow. On 1 heinä, 14:22, Thorsten Müller <thors...-1oxKqHKwyltBDgjK7y7TUQ@public.gmane.org> wrote:> > I get error : You have a nil object when you didn''t expect it! > > The error occurred while evaluating nil.category_id > > You use @item.category_id here without assigning anything to @item, so > it''s nil > > > So i have 3 tables categories, items, notes > > Items belongs to category and note, so I have add those to the model > > of item. Do i have to add category model has_many Items call also? > > Yes, Category needs a > has_many :items > > if Items defined > belongs_to :category > > Shouldn''t note belong_to Item instead the other way around? > I just assume this from the name, you may know better.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---