我一直坚持这个问题,并且已经彻底混淆了嵌套模型和验证如何协同工作.
在下面的代码中,我的目标是,如果子模型(内容)的验证失败,则父模型(图像或视频)的创建将失败.目前,父模型正在保存,而子模型则没有,并且验证错误是闻所未闻的.如果没有验证错误,那么一切都按预期工作.
#Image.rb
has_one :content,
as: :contentable,
inverse_of: :contentable,
dependent: :destroy
#Video.rb
has_one :content,
as: :contentable,
inverse_of: :contentable,
dependent: :destroy
#Content.rb
belongs_to :contentable,
inverse_of: :content,
polymorphic: true
validate :all_good?
def all_good?
errors.add(:base, "Nope!")
return false
end
Run Code Online (Sandbox Code Playgroud)
任何线索或见解都非常感谢!
我正在尝试在我的Rails服务器上生成预先签名的URL以发送到浏览器,以便浏览器可以上传到S3.
看起来好像aws-sdk-s3是未来的宝石.但不幸的是,我没有遇到可以提供清晰度的宝石文档.似乎有几种不同的方式这样做,并希望对以下方法的差异提供任何指导 -
使用Aws::S3::Presigner.new(https://github.com/aws/aws-sdk-ruby/blob/master/aws-sdk-core/lib/aws-sdk-core/s3/presigner.rb)但似乎没有采取在对象参数或身份验证凭据中.
使用Aws::S3::Resource.new,但似乎aws-sdk-resources不会被维护.(https://aws.amazon.com/blogs/developer/upgrading-from-version-2-to-version-3-of-the-aws-sdk-for-ruby-2/)
使用Aws::S3::Object.new然后调用该put对象上的方法.
AWS::SigV4直接使用.
我想知道他们是如何不同的,以及选择一个而不是另一个的含义?任何建议都非常感谢,尤其是aws-sdk-s3.
谢谢!
ruby ruby-on-rails amazon-s3 amazon-web-services aws-sdk-ruby
作为 AWS 的一个相对新手,根据设置文档让 Shoryuken gem(带有 Active Job 和 Active Record)工作起来有点曲折。
中间件:我不确定中间件是否是设置的必要部分,因为它只在基本示例中产生。如果您需要在从队列中获取消息之前或之后执行操作,我的理解是否正确。
Shoryuken 插入但不从 SQS 获取消息:此时,Shoryuken 正在将消息传送到 SQS 队列,我可以在 AWS 控制台中看到消息(在可见的消息中),但 Shoryuken 没有获取它们以执行,即使其中没有任何内容队列。
安慰
irb(main):003:0> InvitationMailer.send_invite(ii).deliver_later
Enqueued ActionMailer::DeliveryJob (Job ID: 5c65184c-8656-42bd-95ce-e0ded78a9a44) to Shoryuken(development_mailers) with arguments: "InvitationMailer", "send_invite", "deliver_now", gid://projectname/Invitation/25
=> #<ActionMailer::DeliveryJob:0x007f7fad761a40 @arguments=["InvitationMailer", "send_invite", "deliver_now", #<Invitation id: 25, invite_code: "324234325", sender_id: 7, invitee_first_name: "Kylo", invitee_last_name: "Ren", invitee_email: "test128@somewhere.com", status: "sent", joined_member_id: nil, created_at: "2016-09-24 03:14:44", updated_at: "2016-09-24 04:16:36", invite_message: nil, sent_at: nil, accepted_at: nil, completed_at: nil, clicked_at: nil, source: nil>], …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中,用户可以上传 PDF,其他用户稍后可以查看。对于我的用例,我需要确保 PDF 没有被锁定或加密,并且任何其他用户都可以查看。
为此,我要求用户上传未锁定的 PDF,并希望在尝试上传到 S3 之前,如果 PDF 已锁定,则抛出错误。
我还没有就在浏览器中执行此操作的最佳方法达成共识?我是否尝试读取缓冲区并在无法读取时抛出错误?或者是否有另一种高性能且有效的方法来检测这一点?
我尝试按照自述文件安装activerecord-postgis-adapter但无法创建模型实例,因为我不断收到下面提到的错误:
NoMethodError:nil的未定义方法"point":NilClass
以下是我的不同文件的样子:
Location.rb(模型,更新代码)
# == Schema Information
#
# Table name: locations
#
# id :integer not null, primary key
# locatable_id :integer
# locatable_type :string
# created_at :datetime not null
# updated_at :datetime not null
# coordinates :geography({:srid point, 4326
#
class Location < ActiveRecord::Base
#self.rgeo_factory_generator = RGeo::Geos.factory_generator
#set_rgeo_factory_for_column(:coordinates,
# RGeo::Geographic.spherical_factory(:srid => 4326) )
locFactory = RGeo::ActiveRecord::SpatialFactoryStore.instance.factory(:geo_type => 'point')
belongs_to :locatable,
polymorphic: true
validates :locatable, presence: true
attr_accessor :longitude, :latitude
end
Run Code Online (Sandbox Code Playgroud)
的Gemfile
gem 'rgeo'
gem 'rgeo-activerecord'
gem 'activerecord-postgis-adapter' …Run Code Online (Sandbox Code Playgroud) 渲染时可以有条件的except,only或include选项吗?所以,就像下面的例子:
render json: @post,
except: [:author]
Run Code Online (Sandbox Code Playgroud)
是否有可能有条件的除外选项或类似的选项?
理想情况下,有条件的方式可以让我处理许多不同的条件和情况。
就像可能是这样的:
render json: @post,
except: return_excluded_keys
Run Code Online (Sandbox Code Playgroud)
return_excluded_keys 函数可以返回需要排除的键。
我正在使用 Rails 4.2.6 和 Active Model Serializers 0.9.3。
activerecord ×1
amazon-s3 ×1
amazon-sqs ×1
aws-sdk-ruby ×1
exif-js ×1
javascript ×1
pdf ×1
postgis ×1
reactjs ×1
rgeo ×1
ruby ×1
shoryuken ×1
validation ×1