undefined method `key?' for nil:NilClass PaperClip

Hello, I have a problem with the paperclip, I put on my GemFile

gem "paperclip", "~> 2.6.0"

I create a migrate

class FileUpload < ActiveRecord::Migration   def up     change_table :projects do |t|       t.has_attached_file :image     end   end

  def down     drop_attached_file :projects, :image   end end

on my model I put

class Project < ActiveRecord::Base

  has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" }

end

and in my view I put

<%= form_for @project, :url => { :action => "create" }, :html => { :multipart => true } do |f| %>

    <%= f.label :title, "Título" %>         <%= f.text_field :title %><br />

    <%= f.label :description, "Descrição" %>         <%= f.text_area :description %><br />

    <%= f.label :image, "Imagem" %>         <%= f.file_field :image %><br />

    <%= f.submit "Criar novo Projeto" %>

<% end %>

But when I go to my action, this errors show.

NoMethodError in ProjectsController#new

undefined method `key?' for nil:NilClass

Rails.root: /home/felipe/rails/Younner Application Trace | Framework Trace | Full Trace

Request

Parameters:

None

Show session dump

Show env dump Response

Headers:

None

Thank you.

That's telling you that there's a problem in the one piece you didn't show us, the controller. Somewhere in your Projects controller, you're calling "key?" on something that hasn't been properly set.

-Dave

I'm sorry Dave, I was updated the post, but

I got make it work, but now another error is showing, when I put a image, on my file_field the rails add a div error.

I don't know why...

Now I put the image on file field, but when I click on submit, the page is reload to my new action, with the error div in the file field.

my controller

class ProjectsController < ApplicationController   def index     @projects = Project.all   end

  def new     @project = Project.new   end

  def create     @project = Project.create( params[ :project ] )

    if @project.valid?       flash[ :notice ] = "Projeto criado com sucesso !"       redirect_to :action => "index"     else       render "new"     end   end end

and my action after clicked on submit:

<div class="field_with_errors"><label for="project_image">Imagem</label></div>         <div class="field_with_errors"><input id="project_image" name="project[image]" type="file" /></div><br />

in your create action why do you create the record before validation ? should not it be ?

  def create     @project = Project.new(params[:project])     if @project.save        flash[ :notice ] = "Projeto criado com sucesso !"        redirect_to :action => "index"     else        render :new     end   end

The same error, it look like the paperclip is not working, but I'm following the documentation:

http://rubydoc.info/gems/paperclip/2.6.0/frames

Thank you.

hi

Attachments: http://www.ruby-forum.com/attachment/7148/IMG00176.jpg