我试图启动我的rails服务器,但我收到以下错误:
/config/initializers/formtastic.rb:27:in`':未初始化的常量Formtastic :: SemanticFormBuilder(NameError)
我唯一记得我最后做的就是捆绑安装,从那时起它就没有用了.我试过去除并重新安装我的宝石,甚至是塑形宝石.当我从我的gemfile中删除formtastic gem时,我收到以下错误:
/config/initializers/formtastic.rb:27:in`':ininitialized constant Formtastic(NameError)
然后我去评论formtastic.rb看看发生了什么,当我试图启动服务器时,我又从另一个文件中得到了另一个错误:
/app/api/V1/base_api.rb:11:in
inherited': undefined method继承'for API :: V1 :: ShoppingListAPI:Class(NoMethodError)
无论我做什么,都会出现另一个名称错误.不知道发生了什么以及如何调试它.我试图搜索互联网,但没有找到解决方案.想知道是否有人发现了同样的问题.
我有这个愚蠢的事情......我确信我只是错过了一些明显的东西,但是yahoogling并没有解决问题.
我所做的就是
rails new TestApp
Run Code Online (Sandbox Code Playgroud)
和
cd TestApp
rails generate scaffold User name:string age:integer
bundle exec rake db:create
bundle exec db:migrate
Run Code Online (Sandbox Code Playgroud)
哪个工作正常.
但是当我去IRB时,没有用户!
u = User.first
NameError: uninitialized constant User
from (irb):3
from /usr/bin/irb:12:in `<main>'
Run Code Online (Sandbox Code Playgroud)
这有什么不对?
干杯
我的程序有一个奇怪的问题,异常堆栈是:
*except Exception, cause: raise ExprEvalError(src, cause)
ExprEvalError: date_after raises NameError: name 'date_after' is not defined*
Run Code Online (Sandbox Code Playgroud)
所以代码是:
@staticmethod
def get_recently(days_before=30):
delta = timedelta(days=days_before)
date_after = datetime.now() - delta
return list(Version.select(lambda v:v.create_time>date_after).order_by(desc(Version.create_time))[:])
Run Code Online (Sandbox Code Playgroud)
ORM框架是Pony,但我认为它与此无关.代码可以在其他PC上正常运行.
你能告诉我这是什么问题吗?谢谢.
PS
我在执行应用程序时遇到此NameError.
NameError in CountriesController#index
undefined local variable or method `country_code' for Country(id: integer, name: string, country_code: string):Class
Run Code Online (Sandbox Code Playgroud)
这是代码中的某个地方,但我不明白.我有我的country_code,但它说它不存在.
class Country < ActiveRecord::Base
validates country_code, presence: true
validates name, presence: true
has_and_belongs_to_many :groups
Run Code Online (Sandbox Code Playgroud)
有谁知道如何解决这一问题?
ruby activerecord ruby-on-rails nameerror rails-activerecord
我有一堆看起来像这样的代码
if __name__ == "__main__":
main()
def main():
print("hello")
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行此代码时,我收到错误
NameError:未定义名称"main"
我没有在函数"def main()"的第一行中定义名称吗?
我有一个为 python 2.7.3 编写的小型 python 程序:
import time
def fun():
print('Hi')
for i in range(3):
Timer(i, fun).start()
Run Code Online (Sandbox Code Playgroud)
当我运行它时,我收到错误:
NameError: name 'Timer' is not defined
如何找出支持此功能的模块?
我是编程的全新手,我目前正在通过LPTHW.
我正在研究这个问题.但是,当我到达"舱室"时,终端告诉我"舱室"变量没有定义.这就是发生的事情.
这是代码:
print "You enter a dark room with two doors. Do you go through door #1 or door #2?"
door = raw_input("> ")
if door == "1":
print "There's a giant bear here eating a cheese cake. What do you do?"
print "1. Take the cake."
print "2. Scream at the bear."
bear = raw_input("> ")
if bear == "1":
print "The bear eats your face off. Good job!"
elif bear == "2":
print "The bear eats your …Run Code Online (Sandbox Code Playgroud) 我有一个简单的Fibonacci函数,它使用memoisation,它本身就可以正常工作.但是,当我想使用timeit计时时,我得到"NameError:全局名称'备忘录'未定义",即使它是.
#!/usr/bin/python
import sys
import timeit
memo = [0] * 100
def fibmem(n,memo):
#function things
for x in range(1,40):
mytime2 = timeit.Timer('fibmem('+str(x)+', memo)','from __main__ import fibmem')
delta2 = mytime2.timeit(1)
print str(x) + ' ' +str(delta2)
memo[:] = []
Run Code Online (Sandbox Code Playgroud)
我已经尝试过查找它可能是什么,但大多数答案涉及到包括from __main__ import,这不是问题.我确定它仍然与范围有关,但我对时间非常新,所以我不知道.
我是python的新手,现在用它制作一些程序.
我有两个文件,它们是trans.py和main.py.
在trans.py,
from math import *
from numpy import *
def matrix_T(d):
global mat_A, mat_B, mat_C, mat_D
temp_A, temp_B, temp_C, temp_D = mat_A, mat_B, mat_C, mat_D
mat_A = 1.0*temp_A + d*temp_C
mat_B = 1.0*temp_B + d*temp_D
mat_C = 1.0*temp_C
mat_D = 1.0*temp_D
Run Code Online (Sandbox Code Playgroud)
在main.py,
from trans import *
global mat_A, mat_B, mat_C, mat_D
mat_A = 1.0
mat_B = 0.0
mat_C = 0.0
mat_D = 1.0
print(mat_A, mat_B, mat_C, mat_D)
matrix_T(0.0)
print(mat_A, mat_B, …Run Code Online (Sandbox Code Playgroud) 我收到这个错误,我不太确定为什么考虑到我在那里有导入数学行。
NameError: name 'sqrt' is not defined
import math
x = float(input())
y = float(input())
z = float(input())
print('{:.2f} {:.2f} {:.2f} {:.2f}'.format(pow(x, z), pow(x, pow(y, z)), abs(x - y), sqrt(pow(x, z))))
Run Code Online (Sandbox Code Playgroud)
编辑:我能够通过使用解决问题,math.sqrt但我不确定为什么在 pow 和 abs 函数工作时需要它。