I'm failing to create an instance of an has_many-associated model


I’m pretty much of a rails newbie and ss the title says I’m failing at
basic things.

Anyway. I have 2 models ‘article’ and ‘upload’. Article has_many
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])
render :nothing => true


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?



Ok, Hates_ from the IRC helped me. It was params[:file] that was nil

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs