我想在文本里面添加span <option>以及标签和样式(它应该代表选择菜单中的颜色).然而它似乎没有工作......
如何使这段代码工作?
JsFiddle:http://jsfiddle.net/bartuz/08e0L9j2/2/
上面的示例似乎只适用于Firefox ...其他浏览器呢?
通过发布rails 4.2 引入了add_foreing_key方法.据我所知,它被用作与model:references和的迁移的组合add_index.
假设我只使用PostreSQL.(add_foreing_key仅限于MySQL和PostreSQL).应停止使用add_foreign_key与migration model:references和开始使用add_index只?如果是/否,为什么?新add_foreign_key方法有什么好处?是否值得交换?
我已经以这种方式创建了数据库中的现有外键:
class CreateUser < ActiveRecord::Migration
def change
create_table do ... end
add_foreign_key :users, :admins, column: :admin_id
end
end
Run Code Online (Sandbox Code Playgroud)
但忘了添加on_delete: :nullify.迁移已被推送并用于生产.我想添加新的迁移,这将为此PK约束添加cascale删除.怎么实现呢?
有非常简单的组件:
从 'prop-types' 导入 PropTypes 从 'react' import { connect } from 'react-redux'
class MyComponent extends React.Component {
componentWillMount() {
if (this.props.shouldDoSth) {
this.props.doSth()
}
}
render () {
return null
}
}
MyComponent.propTypes = {
doSth: PropTypes.func.isRequired,
shouldDoSth: PropTypes.bool.isRequired
}
const mapStateToProps = (state) => {
return {
shouldDoSth: state.shouldDoSth,
}
}
const mapDispatchToProps = (dispatch) => ({
doSth: () => console.log('you should not see me')
})
export default connect(mapStateToProps, mapDispatchToProps)(MyComponent)
Run Code Online (Sandbox Code Playgroud)
我想测试 ifdoSth被调用 when shouldDoSthis equal …
你可以做到这两点
def setup(options = {})
options.reverse_merge :size => 25, :velocity => 10
end
Run Code Online (Sandbox Code Playgroud)
和
def setup(options = {})
{ :size => 25, :velocity => 10 }.merge(options)
end
Run Code Online (Sandbox Code Playgroud)
在方法的参数中指定默认值.
问题是:哪一个更好?你更愿意使用哪一个?性能,代码可读性或其他方面有什么不同吗?
编辑:我!偶然添加了bang()...并不是要问有关无爆炸方法与爆炸方法之间的区别
我的类中的逻辑有时会Rollbar.silenced用来忽略某些异常(因此它们不会被报告)。
我正在尝试编写一个测试,以确保 rollbar 实际报告错误。
it 'does not mute rollbar' do
expect(Rollbar).not_to receive(:silenced)
expect(Rollbar).to receive(:error).with(any_args).and_call_original
expect { query }.to raise_error(unknown_exception)
end
Run Code Online (Sandbox Code Playgroud)
不幸的是,在报告无法挽救的错误时:error,rollbar 不使用 in 、等方法。:critical:warning
我看到 report_exception_to_rollbar和call_with_rollbar内翻车源代码被包裹着Rollbar.scoped。
所以我尝试用以下方法测试它:
expect(Rollbar).to receive(:scoped).with(any_args).and_call_original
但它也告诉我:
Failure/Error: expect(Rollbar).to receive(:scoped).with(any_args).and_call_original
(Rollbar).scoped(*(any args))
expected: 1 time with any arguments
received: 0 times with any arguments
Run Code Online (Sandbox Code Playgroud)
如何确保异常被 rollbar 捕获并使用 rspec 进行测试?
我想使用的一些第三方服务要求用户登录其网页。方便的 url 在下面的控制器中生成。用户去那里并在身份验证成功后返回我的服务
class MyController < App::BaseController
def login
redirect_to SOME_API.external_url(ENV['secret_id'])
end
end
Run Code Online (Sandbox Code Playgroud)
当用户返回我的服务时,他会在 URL 参数中带来一些来自第三方服务的反馈(例如:)myapp.com/login_callack?response=error&reason=wrong_password。这些参数有很多变体,因此我需要在操作中处理它们
def login_callback
#SOME MAGIC WITH COOKIES/ERRORS/What ever
redirect_to root_path
end
Run Code Online (Sandbox Code Playgroud)
我想使用 RSpec 和 capybara 为其编写功能规范。
scenario 'User authenticates with third-party thing' do
visit '/anything'
click_link 'Go to MyController#login and than get redirect to somerandom.url/login_logic'
# use cassette below
fill_out_form
click_button confirm
# magic happens on their side and their redirect user to my app into #login_callback action
expect(page).to have(/all fancy things i …Run Code Online (Sandbox Code Playgroud) 我看到两种写同样的东西:
def find_nest(animal)
return unless animal.bird?
GPS.find_nest(animal.do_crazy_stuff)
end
Run Code Online (Sandbox Code Playgroud)
VS
def find_nest(animal)
if animal.bird?
GPS.find_nest(animal.do_crazy_stuff)
end
end
Run Code Online (Sandbox Code Playgroud)
哪一个更正确/更可取/遵循最佳实践?或者没关系?
我想将 h2 居中 #top 但 vert-aliignt middle 不能使用相同的自动边距...我不知道该怎么做!
#top {
display: block;
position: relative;
height: 100px;
background-color: rgba(89,144,222,.6);
}
#top h2{
text-shadow: 2px 2px black;
text-align: center;
color: white;
font-family:"Impact";
font-size: 50px;
}
Run Code Online (Sandbox Code Playgroud)
效果是—— 
我可以ivar在这里看到很多次提到的术语https://github.com/rails/rails/issues/18950#issuecomment-77924771但是找不到直接解释什么是iVar.
它是什么,可以在控制器环境之外使用这个术语吗?
ruby model-view-controller controller ruby-on-rails ruby-on-rails-4
ruby ×5
css ×2
html ×2
javascript ×2
rspec ×2
coding-style ×1
controller ×1
css3 ×1
database ×1
enzyme ×1
foreign-keys ×1
guard-clause ×1
jestjs ×1
margin ×1
migration ×1
redux ×1
rollbar ×1
testing ×1
text ×1
text-align ×1
vcr ×1