Felipe Pieretti Umpierre
2012-Feb-17 18:10 UTC
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. -- Posted via http://www.ruby-forum.com/. -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Dave Aronson
2012-Feb-17 18:49 UTC
Re: undefined method `key?'' for nil:NilClass PaperClip
On Fri, Feb 17, 2012 at 13:10, Felipe Pieretti Umpierre <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> NoMethodError in ProjectsController#new > > undefined method `key?'' for nil:NilClassThat''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 -- Dave Aronson: Available Cleared Ruby on Rails Freelancer (NoVa/DC/Remote) -- see www.DaveAronson.com, and blogs at www.Codosaur.us, www.Dare2XL.com, www.RecruitingRants.com -- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Felipe Pieretti Umpierre
2012-Feb-17 18:59 UTC
Re: undefined method `key?'' for nil:NilClass PaperClip
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 /> -- Posted via http://www.ruby-forum.com/. -- 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.
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 On 17 fév, 19:59, Felipe Pieretti Umpierre <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> 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 /> > > -- > Posted viahttp://www.ruby-forum.com/.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Felipe Pieretti Umpierre
2012-Feb-17 23:23 UTC
Re: undefined method `key?'' for nil:NilClass PaperClip
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. -- Posted via http://www.ruby-forum.com/. -- 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.
bujjibabu balaga
2012-Mar-14 10:04 UTC
Re: undefined method `key?'' for nil:NilClass PaperClip
hi Attachments: http://www.ruby-forum.com/attachment/7148/IMG00176.jpg -- Posted via http://www.ruby-forum.com/. -- 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.