我有几个模型分组在这样的模块中:
#/app/models/blobs/small_text.rb
class Blobs::SmallText < ActiveRecord::Base
#.. class implementation
end
Run Code Online (Sandbox Code Playgroud)
我想用法语将人类名称设置为"Texte Court":
I18n.locale = "fr"
Blobs::SmallText.model_name.human # should return "Texte Court"
Run Code Online (Sandbox Code Playgroud)
我遇到了类定义的模块部分以及它应该如何包含在语言环境文件中的问题.我在我的语言环境文件中尝试了几种组合但是没有用.以下是我尝试过的一些组合:
# /config/locales/models/blobs.fr.yml
# first attempt (does not work)
fr:
activerecord:
models:
blobs_small_text: "Texte Court"
Run Code Online (Sandbox Code Playgroud)
# /config/locales/models/blobs.fr.yml
# second attempt(does not work)
fr:
activerecord:
models:
blobs:
small_text: "Texte Court"
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?感谢:D.
ruby-on-rails internationalization ruby-on-rails-3 ruby-on-rails-3.1
我有一个current_user
在我的应用程序控制器中调用的辅助方法(与Authlogic一起使用).
使用该帮助程序的视图的规范失败(但是当我使用浏览器时视图正在工作)
ActionView::Template::Error: undefined local variable or method 'current_user' for #<#<Class:0x0000000229b060>:0x00000002004248>
我使用rspec 2.6.0.
有人有同样的问题吗?请指教.谢谢
我想知道是否有办法在Rails应用程序中列出所有已定义的环境.
例如,如果一个应用程序有4个已定义的环境(生产,登台,开发,测试),我想获得以下数组
["production", "staging", "development", "test"]
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?谢谢
ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.1 ruby-on-rails-3.2
我正在尝试使用Cucumber和Factory Girl.以下行:
Given I am not logged in
And the following user exists:
| login | email | password | confirmation |
| user50 | user50@mydomain.com | secret50 | secret 50 |
....
Run Code Online (Sandbox Code Playgroud)
引发以下错误:
Undefined step: "the following user exists:" (Cucumber::Undefined exception)
/home/user/RubymineProjects/project/features/sign_in.feature:9:in `And the following user exists:
You can implement step definitions for undefined steps with these snippets:
And /^the following user exists:$/ do |table|
# table is a Cucumber::Ast::Table
pending # express the regexp above with the code …
Run Code Online (Sandbox Code Playgroud) 我正在切换到Heroku主机.我在我的本地机器上有当前生产数据库的副本(> 100 M),我无法将其推送到heroku.
我一遍又一遍地得到同样的错误:
Taps Server Error: undefined method `symbolize_keys' for nil:NilClass
Run Code Online (Sandbox Code Playgroud)
这似乎与数据库中的某些NULL值(不是全部)有关.有想法该怎么解决这个吗?谢谢!
这是完整的输出:
!!! Caught Server Exception
HTTP CODE: 500
Taps Server Error: undefined method `symbolize_keys' for nil:NilClass
/app/lib/taps/data_stream.rb:183:in `parse_json'/app/lib/taps/server.rb:69:in
POST /sessions/:key/push/verify_stream /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:863:in
call/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:863:in
route /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:521:in
instance_eval /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:521:in
route_eval /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:500:in
route!/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:497:in
catch/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:497:in
route!/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:476:in
each/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:476:in
route!/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:601:in
dispatch! /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:411:in
call! /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in
instance_eval /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in
invoke/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in
catch /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:566:in
invoke /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:411:in
call!/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:399:in
call/app/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/auth/basic.rb:25:in
call /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:979:in
call /app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:1005:in
synchronize/app/.bundle/gems/ruby/1.8/gems/sinatra-1.0/lib/sinatra/base.rb:979:in
call/home/heroku_rack/lib/static_assets.rb:9:in
call'/home/heroku_rack /lib/last_access.rb:15:in
call'/app/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/urlmap.rb:47:in
call'/app/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/urlmap.rb:41:in
each'/app/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/urlmap.rb:41:in
call'/home/heroku_rack/lib/date_header.rb:14:in
call'/app/.bundle/gems/ruby/1.8/gems/rack-1.2.1/lib/rack/builder.rb:77:in
call'/app/.bundle/gems/ruby/1.8/gems/thin-1.2.7/lib/thin/connection.rb:76:in
pre_process'/app/.bundle/gems/ruby/1.8/gems/thin-1.2.7/lib/thin/connection.rb:74:in
catch'/app/.bundle/gems/ruby/1.8/gems/thin-1.2.7/lib/thin/connection.rb:74:in
pre_process'/app/.bundle/gems/ruby/1.8/gems/thin-1.2.7/lib/thin/connection.rb:57:in
process'/app/.bundle/gems/ruby/1.8/gems/thin-1.2.7/lib/thin/connection.rb:42:in
receive_data'/app/.bundle/gems/ruby/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in
run_machine'/app/.bundle/gems/ruby/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in
run'/app/.bundle/gems/ruby/1.8/gems/thin-1.2.7/lib/thin/backends/base.rb:57:in …
Run Code Online (Sandbox Code Playgroud) 在迁移到Rails 5.0.0.beta1时,我发现了很多弃用警告:
DEPRECATION WARNING: env is deprecated and will be removed from Rails 5.0. (called from XXX at YYY)
Run Code Online (Sandbox Code Playgroud)
我试图摆脱它,并试图找到一个替代方案,但在actionpack changelog中找不到任何东西.
有任何想法吗 ?
首先,我同意模仿外部API调用是大多数时候做的正确的事情.但不是在这种情况下.
我Timeout::Error
在一些测试中得到随机异常,我希望能够忽略它们并自动重新运行该示例.只有在10次尝试失败后才应报告失败.
应报告任何其他异常和故障.
我试图使用文件中的全局around(:each)
钩子来实现此行为spec/spec_helper.rb
:
RSpec.configure do |config|
config.around(:each) do |example|
attempts = 0
passed = false
begin
attempts +=1
example.run
passed = true
rescue Timeout::Error => e
raise e if attempts >= 10
end until passed
end
end
Run Code Online (Sandbox Code Playgroud)
但是,当发生异常时,救援部分永远不会被执行.知道为什么吗?
谢谢!多利安
PS我正在使用rspec 2.6.0
是否可以防止公共方法被子类覆盖?
class Parent
def some_method
#important stuff that should never be overwritten
end
end
class Child < Parent
def some_method
#should not be possible to overwrite (raise an error if a child class tries to do it)
end
end
Run Code Online (Sandbox Code Playgroud)
谢谢!
ruby inheritance multiple-inheritance single-table-inheritance ruby-on-rails-3
所以我一直在使用Traiblazer和Reform文档,我经常看到这种代码
class AlbumForm < Reform::Form
collection :songs, populate_if_empty: :populate_songs! do
property :name
end
def populate_songs!(fragment:, **)
Song.find_by(name: fragment["name"]) or Song.new
end
end
Run Code Online (Sandbox Code Playgroud)
注意def populate_songs!(fragment:, **)
定义?
我很清楚双splat命名参数(比如**others
)捕获所有其他关键字参数.但我从未见过**
一个人,没有名字.
所以我的两个问题是:
有一个带有公共读取策略的存储桶。现在我想限制对某些对象的访问,以便只能从某些 IP 地址访问。这可能吗?
我还计划添加 CloudFront。我应该怎么做才能在每个对象上保持相同的设置?
谢谢!
rspec ×2
rspec2 ×2
ruby ×2
actionpack ×1
amazon-iam ×1
amazon-s3 ×1
authlogic ×1
cucumber ×1
factory-bot ×1
heroku ×1
inheritance ×1
reform ×1
rspec-rails ×1
taps ×1
trailblazer ×1