この質問に回答して以来、ペーパークリップはかなり成熟しました。URL を渡してファイルを保存する場合は、Paperclip v3.1.4 の時点で、URL を Paperclip の添付ファイル属性に割り当てるだけで済みます。
User
クラスがあり、私の添付ファイルが と呼ばれているとしましょうavatar
。User
モデルには次のものがあります。
has_attached_file :avatar
# Validate the attached image is image/jpg, image/png, etc
# This is required by later releases of Paperclip
validates_attachment_content_type :avatar, :content_type => /\Aimage\/.*\Z/
私たちの見解では、Aviary から受け取った一時 URL を受け入れる隠しフィールドを定義できます。
= f.hidden_field :avatar, id: 'avatar'
この非表示フィールドの値は、AviaryonSave
コールバックで設定できます。
var featherEditor = new Aviary.Feather({
apiKey: '#{ENV['AVIARY_KEY']}',
onSave: function(imageID, newURL) {
var img = document.getElementById(imageID);
img.src = newURL;
var avatar = document.getElementById('avatar');
avatar.value = newURL;
featherEditor.close();
}
});
onSave 内では、AJAX を使用してUser
オブジェクトを更新したり、jQuery を使用.submit()
してフォームを送信したり、ユーザーが必要なときに送信したりできます。