Re: [Rails] active admin undefined method `[]' for nil:NilClass
On 19 April 2012 18:34, ruby LED <lists@ruby-forum.com> wrote:
> im working with active admin i have collection_select or dropdown box
> that populates the packages and crews im just wondering i why this
>
> undefined method `[]' for nil:NilClass`
> i dont know what happened but it run few days ago and tested it once but
> now it raises this error are there possible way to solve this?
>
> def create
> @package = Package.find(params[:package_crew][:package_id])
> crew = Crew.find(params[:package_crew][:crew_id] )
> @package_crew = @package.add_crew(crew.id)
> if @package_crew.save
> redirect_to {admin_package_crew_url}
> end
> end
> thanks in advance more power to us all
>
> i tried this
>
> def create
> #pid = params[:package_crew][:crew_id] if params[:package_crew]
> pid,cid = 2 #tried nil,0..10
> if params[:package_crew]
> pid = params[:package_crew][:package_id]
> cid = params[:package_crew][:crew_id]
> end
> @package = Package.find_by_id(pid)
> crew = Crew.find_by_id(cid)
> #@package = Package.find(params[:package_crew][:package_id])
> #crew = Crew.find(params[:package_crew][:crew_id] )
> @package_crew = @package.add_crew(crew.id)
> if @package_crew.save
> redirect_to {admin_package_crew_url}
> end
> end
>
> add_crew method
>
> def add_crew(crew_id)
> current_package = package_crews.find_by_crew_id(crew_id)
> if current_package
> current_package.quantity = current_package.quantity.to_i + 1
> else
> current_package = package_crews.build(:crew_id => crew_id)
> current_package.price = current_package.crew.price
> end
> current_package
> end
> moving parameters
>
> {"utf8"=>"✓",
> "authenticity_token"=>"n4WZpQpES6mnSO12oGKV/MeoxAVvV9OmJQKfhcpnvQM=",
> "crew_for_package"=>{"package_id"=>"1",
> "crew_id"=>"1",
> "quantity"=>"1"},
> "commit"=>"Create Package crew"}
> stack error
>
> app/admin/package_crews.rb:35:in `create'
The error says that on line 35 you are calling [] on something that is nil.
Please tell us which is line 35, that may make it easier to find the
problem. First, however, have a look at the rails guide on debugging
to get ideas on how to debug the code and work out what the problem
is.
Colin
--
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@googlegroups.com.
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.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home