您需要返回重定向,而不是flash消息。在Ruby中,方法中执行的最后一行是返回的内容。您有一条flash消息,因此从create操作返回的不是重定向调用。
修好它,你应该很好!
class SalesmenController < ApplicationController
# def index...
def create
@salesman = Salesman.new(params_salesman)
authorize! :create, @salesman
if @salesman.save
flash[:notice] = "Salesman saved!"
redirect_to company_salesman_path(current_company, @salesman) # This has to executed last for the redirect
else
flash.now[:error] = "Could not create salesman!"
render :new
end
# ....
end
end
规范需要更新以反映重定向。成功用于渲染页面。
it "redirect to new team" do
expect(response).to redirect_to(company_salesman_path(company, salesman))
end
顺便说一句,你不需要在FG中创建记录。你能做到的
attributes_for(:salesman)
快乐的黑客!