我正在使用带引导程序3的simple_form gem.我想要一个提交按钮的包装器
现在它将HTML显示为
<form id="new_order" ...>
...
<input class="btn btn-primary" type="submit" value="Save" name="commit">
</form>
Run Code Online (Sandbox Code Playgroud)
我想写一个包装器,所以HTML将是:
<form id="new_order" ...>
...
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<input class="btn btn-primary" type="submit" value="Save" name="commit">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我到目前为止得到了这个:
应用程序/初始化/ simple_form_bootstrap.rb:
options[:wrapper] = :horizontal_form
options[:wrapper_mappings] = {
check_boxes: :horizontal_radio_and_checkboxes,
radio_buttons: :horizontal_radio_and_checkboxes,
file: :horizontal_file_input,
boolean: :horizontal_boolean,
# what to write here??
# submit: :horizontal_submit_button
}
Run Code Online (Sandbox Code Playgroud)
这是我的包装:
config.wrappers :horizontal_submit_button, tag: 'div', class: 'form-group', error_class: 'has-error' do |b|
b.use :html5
b.use :placeholder
b.wrapper tag: 'div', class: 'col-sm-offset-2 col-sm-10' do …Run Code Online (Sandbox Code Playgroud) 我在应用程序配置中定义了一个选项.我要测试的类是在gem中定义的(不是由我编写的).我想重新开课:
Myclass.class_eval do
if Rails.application.config.myoption=='value1'
# some code
def self.method1
end
else
# another code
def self.method2
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想使用RSpec 3测试此代码:
# myclass_spec.rb
require "rails_helper"
RSpec.describe "My class" do
allow(Rails.application.config).to receive(:myoption).and_return('value1')
context 'in taxon' do
it 'something' do
expect(Myclass).to respond_to(:method1)
end
end
end
Run Code Online (Sandbox Code Playgroud)
如何在运行重新打开类的代码之前存根应用程序配置值.
如何在局部视图中将所有本地作为哈希.
# mainview.html.haml:
= render 'v1', p1: 100, p2: 'some_value', _other_values_
Run Code Online (Sandbox Code Playgroud)
在局部视图中:
# _v1.html.haml
# do something here...
# render another partial view
= render 'another_view', locals: locals # what to write here???
Run Code Online (Sandbox Code Playgroud)
如何访问本地中的所有变量作为哈希.我不想在本地列出所有变量.
我想测试我在其中运行两次 Temp::Service.run 方法的方法:
module Temp
class Service
def self.do_job
# first call step 1
run("step1", {"arg1"=> "v1", "arg2"=>"v2"})
# second call step 2
run("step2", {"arg3"=> "v3"})
end
def self.run(name, p)
# do smth
return true
end
end
end
Run Code Online (Sandbox Code Playgroud)
我想测试提供给方法的第二次调用的参数:使用第一个参数“step2”运行,而我想忽略相同方法的第一次调用:运行但使用第一个参数“step1”。
我有 RSpec 测试
RSpec.describe "My spec", :type => :request do
describe 'method' do
it 'should call' do
# skip this
allow(Temp::Service).to receive(:run).with('step1', anything).and_return(true)
# check this
expect(Temp::Service).to receive(:run) do |name, p|
expect(name).to eq 'step2'
# check p
expect(p['arg3']).not_to be_nil
end
# …Run Code Online (Sandbox Code Playgroud) 我创建了一个gem(不是引擎),里面有一些js文件:
lib/assets/javascripts/mygem.js
Run Code Online (Sandbox Code Playgroud)
在我的应用程序中,我想将这个js包含到application.js中:
# app/assets/javascripts/application.js
// require mygem # DOESN'T WORK
Run Code Online (Sandbox Code Playgroud)
这不起作用.
是否可以包含宝石资产?或者我应该为gem编写一个生成器,它将所有资产从gem复制到application assets文件夹中.
Sensu说:当检查结果显示状态发生变化时,会创建一个Sensu事件.
是否可以创建一个不是检查结果的自定义事件?
Sensu API无法创建事件:https://sensuapp.org/docs/latest/api-events .