我有一个Ruby on Rails应用程序,我想同时为所有客户端生成发票,表之间有一个one_to_many关联。我的客户端表名为Clientpf,发票表名为Factpf,我在Factpf模型中有一个如下所示的generate方法
def self.generate(client)
@clientpfs = client
@clientpfs.each do |clientpf|
factpf.create!
sold = clientpf.sold
tt = clientpf.ab
rez = tt * 3
if sold > 0 and rez > sold
factpf.suma = clientpf.ab
factpf.data = Time.now
factpf.save!
end
end
end
并且factpf_controller中的call方法看起来像这样
def generate
client = Clientpf.all
Factpf.generate(params[:client])
redirect_to root_url, notice: "Facturile lunare au fost emise."
end
我看起来像这样的错误,
找不到带有id = generate
的Factpf提取的来源(第88行): 86 87 88 89 90 91
# Use callbacks to share common setup or constraints between actions.
def set_factpf
@factpf = Factpf.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
Rails.root:/ home / dbdominet
应用程序跟踪|框架跟踪|完整追踪 app / controllers / factpfs_controller.rb:88:在`set_factpf'中 请求
参数:
{ “ID”=> “中生成”}
答案 0 :(得分:0)
您应该使用create / build来创建相关实体
示例:
client = Clientpf.find params[:client_id]
factpf = client.factpfs.create suma: clientpf.ab, data: Time.now
有关详细信息,请参阅http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html