据我所知,在JSON中,键应该用双引号括起来.但是,我正在使用一个不引用它们的数据源,这导致Ruby JSON解析器引发错误.有没有办法执行'非严格'解析?
例:
>> JSON.parse('{name:"hello", age:"23"}')
JSON::ParserError: 618: unexpected token at '{name:"hello", age:"23"}'
from /Library/Ruby/Gems/1.8/gems/json-1.1.7/lib/json/common.rb:122:in `parse'
from /Library/Ruby/Gems/1.8/gems/json-1.1.7/lib/json/common.rb:122:in `parse'
from (irb):5
>> JSON.parse('{"name":"hello", "age":"23"}')
=> {"name"=>"hello", "age"=>"23"}
>>
Run Code Online (Sandbox Code Playgroud)
(我尝试使用正则表达式在解析之前添加引号,但无法使其完全正常工作).
我的完整代码可以在https://github.com/andyw8/simpleform_examples上看到
我有一个ProductCategory带有以下验证的连接模型:
validates :product, presence: true
validates :category, presence: true
Run Code Online (Sandbox Code Playgroud)
我的Product模型有以下关联:
has_many :product_categories
has_many :categories, through: :product_categories
Run Code Online (Sandbox Code Playgroud)
当我尝试使用类别创建新产品时,@product.save!控制器中的调用将失败:
Validation failed: Product categories is invalid
Run Code Online (Sandbox Code Playgroud)
当我删除验证时,一切正常,连接模型正确保存.
我正在使用,strong_parameters但我不认为这应该与这个问题有关.
在开发模式下,我可以向设备发送推送通知,而我无法投入生产,我的设置是:
问题是我的rails应用程序发送通知并且没有收到任何错误,但没有任何设备到达.
我正在使用testflight来分发我的应用程序的ad-hoc版本,但我不知道使用testlight和APNS有任何问题.
什么可以?
编辑我解决了:端口错了,2195而不是2196 ......
我刚刚创建了一个新的rails应用程序(在CL上,使用rails new),我在4.2.6,但似乎在我可以对应用程序做任何事情之前我遇到了错误.
第一...
/config/environments/development.rb:53:in `block in <top (required)>':
uninitialized constant ActiveSupport::EventedFileUpdateChecker (NameError)
Run Code Online (Sandbox Code Playgroud)
一旦我评论出来......
/config/initializers/new_framework_defaults.rb:15:in `<top (required)>':
undefined method `to_time_preserves_timezone=' for ActiveSupport:Module (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
一旦被评论出来......
/config/initializers/new_framework_defaults.rb:21:in `<top (required)>':
undefined method `halt_callback_chains_on_return_false=' for ActiveSupport:Module (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
最后...
.gem/ruby/2.2.3/gems/actionmailer-4.2.5/lib/action_mailer/base.rb:569:in `method_missing':
undefined method `perform_caching=' for ActionMailer::Base:Class (NoMethodError)
Run Code Online (Sandbox Code Playgroud)
我可以在Google上看到的所有内容都表明这些是Rails 5相关的东西.我不确定如何解决它们,或者如何创建仍然特定于4.2.6的应用程序.
我的测试中有一条线:
page.has_reply?("my reply").must_equal true
Run Code Online (Sandbox Code Playgroud)
并使其更具可读性我想使用自定义匹配器:
page.must_have_reply "my reply"
Run Code Online (Sandbox Code Playgroud)
基于https://github.com/zenspider/minitest-matchers的文档,我希望我需要编写一个类似于以下内容的匹配器:
def have_reply(text)
subject.has_css?('.comment_body', :text => text)
end
MiniTest::Unit::TestCase.register_matcher :have_reply, :have_reply
Run Code Online (Sandbox Code Playgroud)
问题是我无法看到如何获得对主题的引用(即页面对象).文档说"注释主题必须是断言中的第一个参数",但这并没有真正帮助.
我想从标签中提取所有HTML5数据属性,就像这个jQuery插件一样.
例如,给定:
<span data-age="50" data-location="London" class="highlight">Joe Bloggs</span>
Run Code Online (Sandbox Code Playgroud)
我想得到一个哈希:
{ 'data-age' => '50', 'data-location' => 'London' }
Run Code Online (Sandbox Code Playgroud)
我本来希望使用通配符作为我的CSS选择器的一部分,例如
Nokogiri(html).css('span[@data-*]').size
Run Code Online (Sandbox Code Playgroud)
但似乎不支持.
我的项目开发的一部分已经完成.我们公司要求我为开发的代码和今后的开发编写黄瓜测试用例.routes文件有两个子域用于admin和hosts.Devise也在使用中.
现在我安装了黄瓜并为第一个故事写了第一个场景,当未注册的用户登陆主页,输入有效的电子邮件并被重定向到下一页......页面没有密码字段.
Scenario: Non registered user lands on beta home page.
Given: I am on the homepage
When: I enter valid email with "bahubalian...@gmail.com".
Then: I should be redirected to request invitation page.
Run Code Online (Sandbox Code Playgroud)
问题出在我的路线文件中,我有,
constraints :subdomain => ADMIN_SUBDOMAIN do
....
root :to => admin#index
end
constraints :subdomain => HOST do
...
root :to => home#index.
end
Run Code Online (Sandbox Code Playgroud)
现在,我如何指定path.rb文件以查找该特定子域中的root_path.没有root_path写在子域约束之外.这是我第一次参加测试.我真的很坚持这一点.非常感谢任何帮助.
我只是从某人那里得知,这可以用capybara来实现.如果是这样,你能不能对它有所了解.
假设您有多个OR的条件,例如
if action == 'new' || action == 'edit' || action == 'update'
Run Code Online (Sandbox Code Playgroud)
另一种写这个的方法是:
if ['new', 'edit', 'action'].include?(action)
Run Code Online (Sandbox Code Playgroud)
但这感觉就像编写逻辑的"向后"方式.
是否有任何内置方式可以执行以下操作:
if action.equals_any_of?('new', 'edit', 'action')
Run Code Online (Sandbox Code Playgroud)
?
更新 - 我非常热衷于这个小片段:
class Object
def is_included_in?(a)
a.include?(self)
end
end
Run Code Online (Sandbox Code Playgroud)
更新2 - 基于以下评论的改进:
class Object
def in?(*obj)
obj.flatten.include?(self)
end
end
Run Code Online (Sandbox Code Playgroud) 有没有办法禁用reek每个方法、每行或每个块的 gem 警告?
rubocop例如我们有什么
# suppress warning Use snake_case for method names
def fooBar(baz) # rubocop:disable Naming/MethodName
baz
end
Run Code Online (Sandbox Code Playgroud)
这个例子将抑制 rubocop 的警告,我正在寻找类似的reek工具。
def foo(bar) # reek:disable TooManyStatements
baz = bar + bar
# other line
# more line
# that produce reek warning
baz
end
Run Code Online (Sandbox Code Playgroud)
在文档中我发现它只能通过配置文件进行配置,但这不是我想要的
ruby ×5
activerecord ×1
adhoc ×1
capybara ×1
cucumber ×1
html5 ×1
ios ×1
json ×1
minitest ×1
nokogiri ×1
reek ×1
rspec-rails ×1
testflight ×1
xml ×1