简体   繁体   English

如何从Rails中的模型保存

[英]how do I save from a model in rails

  begin
  # make a new outgoing call
  @call = @client.account.calls.create(
    :from => '+1*********',
    :to => userphone,
    :url => builturl
  )
  rescue StandardError => failedWith
    # Create error entry
    Deliveryerror.new(:objecttype => 1, :deliverytype => 1, :objectid => announce.id, :errormessage => failedWith, :user_id => user.id).save

  end

This call is from a model called Usernotes and I am creating an instance of Deliveryerror. 该调用来自一个名为Usernotes的模型,我正在创建一个Deliveryerror实例。 The call + save above work on rails console. 通话+在Rails控制台上保存以上工作。 I know the call goes into 'recue' but it is never saving a Deliveryerror entry to the db. 我知道调用进入“救援”,但从未将DeliveryError条目保存到数据库。

Env 环保
Rails 3.1 Rails 3.1
Lion Server 狮子服务器
Ruby 1.9.2 Ruby 1.9.2
PostgreSQL PostgreSQL的
*Using delayed_job on this method call *在此方法调用上使用delay_job

您要使用.create而不是.new.create将保存对象,而.new不会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Rails 中的 model 方法保存到数据库 - How do I save to database from a model Method in rails Rails —如何从after_save回调中查看新旧模型的值? - Rails — How do I see old and new model values from an after_save callback? Rails:如何将来自模型中的 before_save 的错误添加到控制器中? - Rails: How do I add into the controller an error that comes from a before_save in the model? Rails:如何将字符串表示形式保存回模型中? - Rails: How do I save a string representation back into a model? Rails Model 中发生回滚时如何保存记录 - How do I save record when rollback happens in Rails Model 如何在Rails中更新并保存另一个模型? - How can I update and save one model from another in Rails? 如何将Nokogiri的抓取数据保存到Rails数据库? - How do I save the scraped data from Nokogiri to a Rails database? 如何在Rails中将其他参数从控制器传递到模型 - How Do I Pass Additional Parameters in Rails from Controller to Model 如何从Rails模型中的其他字段生成字段 - How do I generate a field from other fields in rails model 我该如何在用户搜索事件并保存感兴趣的事件的地方建模我的Rails应用程序? - How do I model my Rails application where users search for events and save the ones that interest them?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM