Luke
2011-Mar-11 20:41 UTC
I''m failing to create an instance of an has_many-associated model
Hi,
I''m pretty much of a rails newbie and ss the title says I''m
failing at very
basic things.
Anyway. I have 2 models ''article'' and
''upload''. Article has_many :uploads
Now I''m trying to create an instance of upload in an article in my
articles_controller like this:
class ArticlesController < ApplicationController
def upload
@article = Article.find(params[:id])
@article.uploads.create(params[:file])
render :nothing => true
end
end
If I submit a file to articles/1/upload I get a NoMethodError
You have a nil object when you didn''t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.delete
app/controllers/articles_controller.rb:95:in `upload''
where line 95 is @article.uploads.create(params[:file])
Does anyone have an idea what''s wrong?
Thanks
Lukas
--
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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.
Luke
2011-Mar-11 20:59 UTC
Re: I''m failing to create an instance of an has_many-associated model
Ok, Hates_ from the IRC helped me. It was params[:file] that was nil -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.