NoMethodError (undefined method `new' for nil:NilClass): when try to create Photo object?

Up vote 0 down vote favorite share g+ share fb share tw.

When I try to assign the data sent with the POST method to an object I get the following error. Started POST "/backend/photos" for 127.0.0.1 at 2012-02-10 19:24:48 +0100 Processing by Backend::PhotosController#create as */* Parameters: {"utf8"=>"? ", "authenticity_token"=>"yeFZOu6sG3tyNqT4uBb5Xq0fp+1yTZ2wxn0WFPvGhPw=", "photo"=>{"source_type"=>"post", "source_id"=>"5", "cropping"=>"1", "img"=>#>}} Completed 500 Internal Server Error in 1ms NoMethodError (undefined method `new' for nil:NilClass): app/controllers/backend/photos_controller.

Rb:5:in `new' app/controllers/backend/photos_controller. Rb:5:in `create' Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_trace. Erb (2.6ms) Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.

Erb (1.0ms) Rendered /usr/local/rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics. Erb within rescues/layout (5.3ms) In controller: # -*- encoding : utf-8 -*- class Backend::PhotosController { :pic_path => @photo.img.url. To_s , :name => @photo.img.instance.

Attributes"img_file_name" }, :content_type => 'text/html' else #todo handle error render :json => { :result => 'error'}, :content_type => 'text/html' end end In model: # -*- encoding : utf-8 -*- class Photo? ", p.id). Order(" id asc ").

Limit(1) } after_save :observe_seq_after_save before_create :set_seq_before_create after_update :change_seq_after_update after_destroy :change_seq_after_destroy attr_accessor :cropping belongs_to :product after_update :reprocess_picture, :if => :cropping? Has_attached_file :img, :styles => { :thumb => { :geometry => '130x130#', :quality => 60, :format => 'JPG', :processors => :cropper}, :normal => { :geometry => '520x520>', :quality => 90, :format => 'JPG'}, :big => { :geometry => '800x600>', :quality => 90, :format => 'JPG'} } validates_attachment_presence :img validates_attachment_size :img, :less_than => 5. Megabytes validates_attachment_content_type :img, :content_type => 'image/jpeg', 'image/png', 'image/pjpeg' In routes: namespace :backend do root :to => "dashboards#show" match "/set_per_page_admin" => "sessions#set_per_page_admin" match "/posts/:post_id/photos/:id/move_up" => "photos#move_up" match "/posts/:post_id/photos/:id/move_down" => "photos#move_down" match "/photos/reset_seq" => "photos#reset_seq" match "/photos/new/:source_type/:source_id" => "photos#new" resources :photos do member do get :crop get :crop_existing_photo end end scope "/remote" do match "/show_pic" => "photos#show_pic" match "/show_crop" => "photos#show_crop" end resources :posts end Installed gems: Gems included by the bundle: * actionmailer (3.2.1) * actionpack (3.2.1) * activemodel (3.2.1) * activerecord (3.2.1) * activeresource (3.2.1) * activesupport (3.2.1) * arel (3.0.0) * builder (3.0.0) * bundler (1.0.21) * cocaine (0.2.1) * coffee-rails (3.2.2) * coffee-script (2.2.0) * coffee-script-source (1.2.0) * date_validator (0.6.3) * erubis (2.7.0) * execjs (1.3.0) * foreigner (1.1.1) * hike (1.2.1) * i18n (0.6.0) * journey (1.0.1) * jquery-rails (2.0.0) * json (1.6.5) * libv8 (2012-02-10 19:24:48 +01007.4) * magic_encoding (0.0.2) * mail (2.4.1) * mime-types (2012-02-10 19:24:48 +01008.2) * multi_json (1.0.4) * mysql2 (0.

3.11) * paperclip (2.6.0 71d3f46) * polyglot (0.3.3) * rack (1.4.1) * rack-cache (1.1) * rack-ssl (1.3.2) * rack-test (0.6.1) * rails (3.2.1) * railties (3.2.1) * rake (0.9.2.2) * rdoc (2012-02-10 19:24:48 +01008) * rmagick (2.12.0) * sass (12-02-10 19:24:48 +0100) * sass-rails (3.2.4) * sprockets (2.1.2) * stringex (1.3.0) * therubyracer (0.9.9) * thor (0.14.6) * tilt (1.3.3) * treetop (2012-02-10 19:24:48 +01009) * tzinfo (0. 2012-02-10 19:24:48 +01008) * uglifier (1.2.3) * will_paginate (3.0.3) It is interesting that in another project the same code works well. Gems in this project: * actionmailer (3.1.0.

Rc8) * actionpack (3.1.0. Rc8) * activemodel (3.1.0. Rc8) * activerecord (3.1.0.

Rc8) * activeresource (3.1.0. Rc8) * activesupport (3.1.0. Rc8) * addressable (2.2.6) * arel (2.2.1) * authlogic (3.1.0) * aws-s3 (0.6.2) * bcrypt-ruby (3.0.1) * builder (3.0.0) * bundler (1.0.21) * date_validator (0.6.3) * devise (1.5.3) * erubis (2.7.0) * execjs (1.3.0) * foreigner (1.1.1) * heroku (2.18.1) * hike (1.2.1) * i18n (0.6.0) * jquery-rails (1.0.19) * json (1.6.5) * launchy (2.0.5) * libv8 (2012-02-10 19:24:48 +01007.4) * magic_encoding (0.0.2) * mail (2.3.0) * mime-types (2012-02-10 19:24:48 +01008.2) * multi_json (1.0.4) * mysql2 (0.

3.11) * nifty-generators (0.4.6) * orm_adapter (0.0.6) * paperclip (2.3.6) * polyglot (0.3.3) * rack (1.3.3) * rack-cache (1.0.3) * rack-mount (0.8.3) * rack-ssl (1.3.2) * rack-test (0.6.1) * rails (3.1.0. Rc8) * rails-i18n (0.3.0) * rails3-jquery-autocomplete (1.0.5) * railties (3.1.0. Rc8) * rake (0.9.2.2) * rdoc (2012-02-10 19:24:48 +01008) * rest-client (1.6.7) * rmagick (2.12.0) * rubyzip (0.9.5) * sprockets (2.0.3) * stringex (1.3.0) * term-ansicolor (1.0.7) * therubyracer (0.9.9) * thor (0.14.6) * tilt (1.3.3) * treetop (2012-02-10 19:24:48 +01009) * tzinfo (0.

2012-02-10 19:24:48 +01008) * uglifier (1.2.2) * warden (1.1.0) * will_paginate (3.0.2) * xml-simple (1.1.1) I added a gem 'aws-sdk', but it did not help anything. Migration file: class CreatePhotos true t. Integer :source_id, :null => true t.

Integer :seq t. String :img_file_name t. String :img_content_type t.

Integer :img_file_size t. Datetime :img_updated_at t. String :title, :null => true t.

Text :desc, :limit=>400, :null=>true t. String :meta_title, :default => nil t. String :meta_desc, :default => nil t.

String :meta_keywords, :default => nil t. Timestamps end add_index(:photos, :source_id) add_index(:photos, :source_type) add_index(:photos, :seq) end def self. Down drop_table :photos end end I have no ideas to solve this problem.

Thanks for any help paperclip nomethoderror ruby-on-rails-3.2.1 link|improve this question edited Feb 10 at 19:14 asked Feb 10 at 18:48Debian52.

Is it in app/models/photo. Rb? – Brandan Feb 11 at 3:44.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions