undefined 方法 'split' for nil:nilClass
undefined method `split' for nil:NilClass
当我运行检索方法时,即使定义了我的类,我也会得到nil类的未定义方法。我真的可以用一些帮助来使它起作用。该命令称为捐赠,但由于某种原因没有被称为。
这是我的捐赠框,称为C 程序
module DonationboxesHelper
private
def editCommons(type)
boxFound = Donationbox.find_by_id(params[:id])
if(boxFound)
logged_in = current_user
if(logged_in && ((logged_in.id == boxFound.user_id) || logged_in.admin))
if(type == "update")
boxFound.initialized_on = currentTime
end
@donationbox = boxFound
@user = User.find_by_vname(boxFound.user.vname)
if(type == "update")
if(logged_in.admin || !boxFound.turn_on)
if(@donationbox.update_attributes(params[:donationbox]))
flash[:success] = "#{@user.vname}'s donationbox was successfully updated."
redirect_to user_path(@user)
else
render "edit"
end
else
redirect_to root_path
end
elsif(type == "retrieve")
if(logged_in.id == boxFound.user_id && boxFound.hit_goal)
pouch = Pouch.find_by_user_id(@user.id)
points = @donationbox.progress
# string_array = calculator(newPet.hp, newPet.atk, newPet.def, newPet.spd)
#petCost, petLevel = string_array.map { |str| str.to_i}
#Calculate the tax
points = 1000
results = `Resources/Code/donationbox/donate #{points}`
string_array = results.split(",")
pointsTax, taxRate = string_array.map{|str| str.to_f}
#Send the points to the user's pouch
netPoints = @donationbox.progress - pointsTax
pouch.amount += netPoints
@pouch = pouch
@pouch.save
@donationbox.progress = 0
@donationbox.goal = 0
@donationbox.hit_goal = false
@donationbox.turn_on = false
@donationbox.save
redirect_to user_path(@user)
else
redirect_to root_path
end
elsif(type == "refund")
if(logged_in.admin || !boxFound.hit_goal)
#Retrieve all donations
allDonors = Donor.all
boxDonors = allDonors.select{|donor| donor.donationbox_id == boxFound.id}
activeDonors = boxDonors.select{|donor| donor.created_on > boxFound.initialized_on}
#Gives back the original users donations
activeDonors.each do |donor|
donor.user.pouch.amount += donor.amount
boxFound.progress -= donor.amount
@donationbox = boxFound
@donationbox.save
@pouch = donor.user.pouch
@pouch.save
@donor = donor
@donor.destroy
end
boxFound.turn_on = false
boxFound.goal = 0
boxFound.progress = 0
if(boxFound.hit_goal)
boxFound.hit_goal = false
end
@donationbox = boxFound
@donationbox.save
redirect_to user_path(@donationbox.user)
else
redirect_to root_path
end
end
else
redirect_to root_path
end
else
render "public/404"
end
end
def mode(type)
if(timeExpired)
logout_user
redirect_to root_path
else
if(type == "index")
logged_in = current_user
if(logged_in && logged_in.admin)
allBoxes = Donationbox.order("initialized_on desc")
@donationboxes = Kaminari.paginate_array(allBoxes).page(params[:page]).per(10)
else
redirect_to root_path
end
elsif(type == "edit" || type == "update" || type == "retrieve" || type == "refund")
if(current_user && current_user.admin)
editCommons(type)
else
allMode = Maintenancemode.find_by_id(1)
userMode = Maintenancemode.find_by_id(5)
if(allMode.maintenance_on || userMode.maintenance_on)
if(allMode.maintenance_on)
render "/start/maintenance"
else
render "/users/maintenance"
end
else
editCommons(type)
end
end
end
end
end
end
运行命令后,它错误。
最重要的是,当我尝试使其看起来像这样时,我会遇到此错误:
eric@eric-PORTEGE-R830:~/Projects/Local/Websites/Resources/C++code/donationbox$ donate 200
donate: command not found
另一个问题是它仅在我做。/donate时才有效,我想使用捐赠而不是。
最重要的是,当我尝试使其看起来像这样时,我会遇到此错误:
eric@eric-portege-r830:〜/projects/local/cormesites/resources/c 代码/捐赠盒$捐赠200捐赠:找不到命令
另一个问题是它仅在我要使用时才有效 捐赠而不是这个,但无法。
如果您希望能够使用donate
运行该应用程序,则需要在将donate
放置到PATH
环境变量的目录中添加路径(此处进行了描述)
相关文章:
- undefined 方法 'split' for nil:nilClass
- What is struct NIL { typedef NIL Head; }?
- Visual C++ & Lua - 尝试索引 nil 值错误
- Lua errorPANIC:调用 Lua API 时出现不受保护的错误(尝试调用 nil 值)
- 如何在C++的红黑树中创建哨兵 NIL 对象
- Lua 5.2 问题:"尝试从lua_pcall调用 nil 值"
- 当给定包含中文字符的wchar_t数组时,NSString initWithBytes返回nil
- 为什么在gtest中将shared_variable重置为nil
- 带有NSData的UIImage initWithData返回nil
- 去虫"attemp to index nil value"
- lubridge getGlobal总是返回nil
- 多次执行lua c++函数导致lua脚本失败,值为nil