ruby on rails - undefined method `[]' for nil:NilClass -


def creation

(1..params[:book_detail][:no_of_copies].to_i).each |i|    logger.info "nnnnnnnnnnn#{i}"   @book_details= bookdetail.new(params[:book_detail])   @book_details.save end 

and error undefined method []' nil:nilclass app/controllers/book_details_controller.rb:16:increation'

is can tell problem?

error getting because params[:book_detail] nil , calling [:no_of_copies] on i.e. nil.so giving following error

 undefined method []' nil:nilclass  

so need check first if params[:book_detail] present or not following

(1..params[:book_detail][:no_of_copies].to_i).each |i|       logger.info "nnnnnnnnnnn#{i}"   @book_details= bookdetail.new(params[:book_detail])   @book_details.save end if params[:book_detail] && params[:book_detail][:no_of_copies] 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -