+1
好高兴能帮到你
#22 楼 @torubylist 第一次在 Ruby 里听说匿名类:
# 本质上说,这两种方式没啥区别
c = Class.new(Array)
class c < Array
end
# Force all environments to use the same logger level
# (by default production uses :info, the others :debug)
config.log_level = :debug
production 上的 log_level 默认是 :info
,临时改成:debug
应该可以满足你的需求;不过长期看来,最好还是建立 uat、staging 之类的环境来来定位这些问题,长期在生产环境这样弄总不是个办法。
Google keyword: Rails config log level
看下配置是这个不? config.log_level = :debug
#13 楼 @torubylist 你这里说的匿名类指的是?
感觉没啥问题。
class Demo
puts 'Hello world'
end
# 上面的代码会输出 Hello world
问题二,其实是在定义类实例变量而已。
并且感觉 has_many :xxx(复数)
应该注意复数
或者用 instance_variable_set
定义成实例变量
感觉过了那个阶段了。
不知这个是否你需要的
Changes the column to a different type using the same parameters as add_column.
change_column(table_name, column_name, type, options):
+1
The Kernel module is included by class Object, so its methods are available in every Ruby object. The Kernel instance methods are documented in class Object while the module methods are documented here. These methods are called without a receiver and thus can be called in functional form:
你是感觉其中的the module methods
较为迷惑对吧?我猜测它说的是module_function
, 若这样的话,它干了两件事情:首先,把紧跟其后的方法都标注成了私有方法; 其次,让紧跟其后的方法可以单例方式访问。
例如:
print 'Hello world' # 毫无疑问,这样可以
Kernel.print 'Hello world' # 这也可以。但如果 print 只是Kernel里一个普通的 private 方法的话,是不能这样玩的。
感觉就是这个段代码逻辑复杂,在测试充分的情况下,采用提取方法
等重构手法进行拆分;否则即使把代码分成多行,还是很难维护;如果实在要强制换行的话,可以加 \
,不过不建议这样弄。类似下面这样:
2.2.0-preview1 :002> a = "hello \
2.2.0-preview1 :002"> world "
=> "hello world "
2.2.0-preview1 :002> a
=> "hello world "
我开头用 Emacs 做过 Ruby 开发,后面团队作战的时候用的 Rubymine,现在再也回不去了。个人觉得有如下优点:
拉钩上个简历吧
有点意思
+1
运行 gem env
没
+1
感觉很奇怪的地方,既然前端只用数据,为啥还需要在前端得到数据后,还希望 redirect_to
另一个地方去。感觉设计上有点怪。