你可以在红宝石中:
class ApplicationController < ActionController::Base
before_filter :require_login
end
Run Code Online (Sandbox Code Playgroud)
我只是想知道什么是before_filter?它是ActionController :: Base的一个方法吗?
如果我创建ApplicationController的对象会发生什么?before_filter方法会运行吗?
谢谢!
任何人都可以为红宝石建议一个记录完备且知名的YAML库吗?
我读过的一本书就像这样:
YAML.load_file(conf.rc).each do |k,v|
conf.send("#{k}=", v)
end
Run Code Online (Sandbox Code Playgroud)
有谁知道使用哪个库?
谢谢
我正在阅读Ruby中的元编程。
这是本书中的两个代码段:
my_var = "Success"
MyClass = Class.new do
puts "#{my_var} in the class definition!"
define_method :my_method do
puts "#{my_var} in the method!"
end
end
MyClass.new.my_method
? Success in the class definition!
Success in the method!
Run Code Online (Sandbox Code Playgroud)
和:
def define_methods
shared = 0
Kernel.send :define_method, :counter do
shared
end
Kernel.send :define_method, :inc do |x|
shared += x
end
end
define_methods
counter # => 0
inc(4)
counter # => 4
Run Code Online (Sandbox Code Playgroud)
我想知道为什么在第一个示例中定义方法时,而不必在第二个示例中使用动态分派(使用Kernel.send)。
我给了一些想法,但听不懂。
谢谢!
使用此gem添加外键约束没有问题:
http://github.com/matthuhiggins/foreigner
但是,我无法删除外键.
class ForeignKeys < ActiveRecord::Migration
def self.up
add_foreign_key(:threads, :users)
end
def self.down
remove_foreign_key(:threads, :column => :user_id)
end
end
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我吗?
谢谢.
在Rails指南中,这出现了:
%w{ models }.each do |dir|
Run Code Online (Sandbox Code Playgroud)
有人能解释一下%w {models}的意思吗?从未见过它.是ruby还是rails特定的.
谢谢
这是我的代码:
account_double.should_receive(:withdraw).and_raise
Run Code Online (Sandbox Code Playgroud)
我得到输出:
1) Statement uses the customer's name in the header
Failure/Error: Unable to find matching line from backtrace
Exception
# ./spec/codebreaker/test.rb:8:in `generate'
# ./spec/codebreaker/test.rb:20
# /usr/local/lib/site_ruby/1.8/rubygems/custom_require.rb:31:in `inject'
Run Code Online (Sandbox Code Playgroud)
它找不到异常.我怎么能通过这个测试?
我不明白这张照片
是否有充分的理由将Rspec用于控制器和视图?
我的观点在很大程度上依赖于Javascript,据我所知,Rspec不会在视图上处理javascript/ajax.我也使用Cucumber + Selenium.
我应该将它用于控制器吗?
仅仅使用Cucumber + Selenium来应用行为是不够的?如果黄瓜测试通过,然后它通过,为什么我要打扰Rspec视图和控制器测试?
有人可以开导我这个话题吗?
我使用Heroku来部署我的Rails应用程序.
但我想学习Chef来自动设置开发基础设施,但我不确定.
所以说得很简单,我有没有理由去学习厨师?
我想知道是否有在Ruby中实现的所有设计模式的作弊cheets,这样你就不必重新发明轮子了.
所以我做了一些研究,发现MongoDB没有做fsync(),这意味着当你告诉数据库写一些东西时,数据库可能会告诉你它已经写好了,尽管它不是.这不是反对CRUD吗?
如果我是对的,有什么好的理由吗?