variables - Rails no implicit conversion of Symbol into Integer -
i trying create private method counting based on database info follows.
class applicationcontroller < actioncontroller::base # prevent csrf attacks raising exception. # apis, may want utilize :null_session instead. protect_from_forgery with: :exception before_action :moderation_count private def moderation_count @count = ''; @count[:venues_pending] = venue.where(:is_approved => 0).count.to_i @count[:venues_rejected] = venue.where(:is_approved => 2).count.to_i @count[:venue_photos_pending] = venuephoto.where(:is_approved => 0).count.to_i @count[:venue_photos_rejected] = venuephoto.where(:is_approved => 2).count.to_i @count[:venue_reviews_pending] = venuereview.where(:is_approved => 0).count.to_i @count[:venue_reviews_rejected] = venuereview.where(:is_approved => 2).count.to_i end end
error:
no implicit conversion of symbol integer
you have set @count
empty string
with
@count = '';
so when @count[:venues_pending]
, ruby
tries convert symbol :venues_pending
integer access particular index of string @count
. resulting in error no implicit conversion of symbol integer
as planning utilize instance variable @count
hash
, should instantiate hash rather empty string.
use @count = {};
or @count = hash.new;
ruby-on-rails variables ruby-on-rails-4
No comments:
Post a Comment