小编ARK*_*ARK的帖子

除非声明我们是否使用else?

关于else不应该使用的声明存在意见unless吗?

任何人都能解释为什么会这样,或者我们可以自由地去任何我们喜欢的地方?

ruby ruby-on-rails

22
推荐指数
4
解决办法
2万
查看次数

如何编写迁移以将已经存在的关联转换为可选?

我创建并迁移了一些belongs_to迁移,但现在我发现在 Rails 5 中,默认行为是required: true我不想要的。

我怎样才能编写一个简单的迁移来将其转换为optional: true

ruby-on-rails ruby-on-rails-5

6
推荐指数
1
解决办法
1422
查看次数

预期响应的状态码为200,但在rspec的请求测试中为302

我发现其他人发布了许多类似的问题,但是没有一个解决方案起作用。

我的/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?

rspec ruby-on-rails rspec-rails

1
推荐指数
1
解决办法
2419
查看次数