更新:在ActiveAdmin中已经有一个解决方案之前询问了这个问题.正如Joseph所述,ActiveAdmin文档现在包含此信息,但此处的答案是为使用旧版ActiveAdmin的人提供的.
当strong_parameters 0.1.4与Rails 3.2.8中的ActiveAdmin 0.5.0一起使用时,如果您使用的模型使用StrongParameters,则包括:
include ::ActiveModel::ForbiddenAttributesProtection
Run Code Online (Sandbox Code Playgroud)
如果您尝试创建/编辑记录,则会在日志中收到以下错误:
ActiveModel::ForbiddenAttributes (ActiveModel::ForbiddenAttributes)
Run Code Online (Sandbox Code Playgroud) ruby-on-rails activeadmin ruby-on-rails-3.2 strong-parameters
我想我会想出一个灵活的方法来扩展Rails 3.x gem中的ApplicationController.
在我的宝石中lib/my_namespace/my_controller.rb
,我有:
class MyNamespace::MyController < ApplicationController
before_filter :some_method
after_filter :another_method
def initialize
# getting classname of the subclass to use for lookup of the associated model, etc.
# and storing the model_class in an instance variable
# ...
end
# define :some_method, :another_method, etc.
# ...
private
attr_accessor :subclass_defined_during_initialize # etc.
# etc.
end
Run Code Online (Sandbox Code Playgroud)
但是当加载Gem时,app/controllers/application_controller.rb
尚未加载,因此失败:
/path/to/rvm/gemset/gems/activesupport-3.2.6/lib/active_support/dependencies.rb:251:
in `require': cannot load such file -- my_gem_name/application_controller (LoadError)
Run Code Online (Sandbox Code Playgroud)
作为一种解决方法,我在我的gem中定义了ApplicationController lib/gem_namespace/application_controller.rb
:
class ApplicationController < ActionController::Base
end
Run Code Online (Sandbox Code Playgroud)
我假设即使我在那里定义它,它也会在我的Rails …
gem ruby-on-rails applicationcontroller ruby-on-rails-3 load-order
虽然git-blame和计数 git存储库中的作者更改的行数是有帮助的,但是有一个命令可以列出所有提交中的repo中修改的所有路径名,作者或作者集对每个文件进行评分根据该作者或作者集的提交数量?例如,在克隆的git仓库中运行这样一个命令的输出类似于:
1 /path/to/some/file/in/repo/file1
34 /path/to/some/file/in/repo/file2
3 /path/to/some/other/file/in/repo/anotherfile
...
Run Code Online (Sandbox Code Playgroud)
谢谢!
我已经看到了一些虚拟Rails应用程序的例子(用于测试,因此它们通常在测试或规范下),与Appraisals宝石一起使用,据说可以与Rails 3.x和Rails 4一起使用,但它们看起来很像hackish功能不全.这是一个有点预期,因为它是一个剥离的弗兰肯斯坦怪物试图兼容各种版本的Rails 3以及Rails 4.
我已经提到了试图进行这种测试的项目(截至2013年3月下旬),比如less-rails和ember-rails,但这种用各种版本的Rails测试的方式看起来不是很干净,而且它是尝试调试非标准的Rails应用程序是非常重要的,特别是在测试版的Rails中.
如果有一个更清晰的测试方法可以让你拥有一个完整的Rails应用程序来为每个版本的Rails进行测试,通过一些魔法来设置或维护并不困难并且不需要非标准的路径攻击在某些地方等
有各种版本的Rails测试宝石的可用策略是什么(至少包括最新的Rails 3.1.x,3.2.x和4.0.0.beta1),每种版本的优缺点是什么?
如何列出Rails 3中的所有自动加载路径?
在Rails控制台中,当我这样做时,它只列出添加到配置的自定义路径:
$ rails c
Loading development environment (Rails 3.2.9)
1.9.3p194 :001 > MyRailsApp::Application.config.autoload_paths
=> []
Run Code Online (Sandbox Code Playgroud) 如果在以下位置使用此选项config/application.rb
:
config.active_record.schema_format = :sql
Run Code Online (Sandbox Code Playgroud)
然后当你这样做:
rake db:migrate
Run Code Online (Sandbox Code Playgroud)
它只会转储db/structure.sql
.我知道它没有使用,db/schema.rb
因为它正在使用该:sql
选项,但你怎么能rake db:migrate
生成db/schema.rb
呢?
我们需要它,因为RubyMine 4.5和IntelliJ IDea 11 db/schema.rb
用于自动完成列.
以下是我正在研究的gem中代码的一般化部分:
module SomeModule
class << self
attr_accessor :procedure
def log_events(*args)
args.flatten!
if args.size == 1
eval "set_trace_func proc {|event, file, line, id, binding, classname| begin; SomeModule.procedure.call(event, file, line, id, binding, classname) if event == #{args[0].inspect}; rescue SystemExit, Interrupt; raise; rescue Exception; end}"
elsif args.size > 1
eval "set_trace_func proc {|event, file, line, id, binding, classname| begin; SomeModule.procedure.call(event, file, line, id, binding, classname) if #{args.inspect}.include?(event); rescue SystemExit, Interrupt; raise; rescue Exception; end}"
else
# ...
end
end
end
end
SomeModule.procedure = …
Run Code Online (Sandbox Code Playgroud) 我非常希望能够使用gitx
Terminal.app中的命令行工具打开GitX并查看我可以滚动的Git存储库更改日志,每个都有格式良好的差异.
Git和Subversion是完全不同的,我知道查看日志的工具和用于检查部分subversion repo的差异肯定与通过GitX查看git repo不同.但是,还有什么允许我在命令行执行中允许我在svn repo的检出目录中看到类似的日志,甚至是一个模糊的类似接口吗?
autoload ×2
gem ×2
ruby ×2
activeadmin ×1
autoloader ×1
command-line ×1
dbmigrate ×1
git ×1
gitx ×1
load-order ×1
rake ×1
schema.rb ×1
svn ×1
testing ×1