关于else
不应该使用的声明存在意见unless
吗?
任何人都能解释为什么会这样,或者我们可以自由地去任何我们喜欢的地方?
我创建并迁移了一些belongs_to
迁移,但现在我发现在 Rails 5 中,默认行为是required: true
我不想要的。
我怎样才能编写一个简单的迁移来将其转换为optional: true
?
我发现其他人发布了许多类似的问题,但是没有一个解决方案起作用。
我的/spec/requests/questions_spec.rb是
require 'rails_helper'
RSpec.describe "Questions", type: :request do
describe "GET /questions" do
it "works! (now write some real specs)" do
get questions_path
expect(response).to have_http_status(200)
end
end
end
Run Code Online (Sandbox Code Playgroud)
现在我的rspec错误
Questions GET /questions works! (now write some real specs)
Failure/Error: expect(response).to have_http_status(200)
expected the response to have status code 200 but it was 302
# ./spec/requests/questions_spec.rb:7:in `block (3 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)
谁能帮我?如何自定义代码以获得状态码200?