gpt4 book ai didi

ruby-on-rails - Rails update_attribute 问题

转载 作者:太空宇宙 更新时间:2023-11-03 18:12:27 30 4
gpt4 key购买 nike

我在使用 Rails 中的 update_attribute 更新程序时遇到问题。这是我的 Controller :

class FeatureUpdatesController < ApplicationController
before_action :set_feature

def backlog
@feature.update_attribute(:deploy_status, "backlog")
redirect_to root_path
flash[:success] = "The status for this feature is now in the backlog"
end

private
def set_feature
@feature = Feature.find(params[:id])
end
end

这是我的测试:

require 'rails_helper'
RSpec.describe FeatureUpdatesController, type: :controller do
describe "PUT #backlog" do
create(:user) && sign_in(user)
it "updates deploy_status to backlog" do
feature = FactoryGirl.create(:feature)
put :backlog, id: feature.id
expect(feature.deploy_status).to eq("backlog")
end
end

deploy_status 不是作为“backlog”返回,而是作为 nil 返回。有什么想法吗?

最佳答案

我认为您必须重新加载该功能:

...
放:backlog,id:feature.id
功能.重新加载
期望(feature.deploy_status).to eq('积压')

关于ruby-on-rails - Rails update_attribute 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31622041/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com