안녕하세요 여러분, 제 특정 문제에 대한 해결책을 찾다가 해결책을 찾지 못했습니다. 나는 모든 것을 시도했다. 이미지를 저장하는 클립이있는 선물 모델이 있습니다. 선물 인스턴스는 아마존 모델 (아마존 API에서 이미지, 이름, 가격 등의 제품 정보를 얻는)에 의해 채워지지만 이미지를 S3에 저장할 수는 없습니다. 내 문제는 실제로 선물을 만들 때와 반대로 내 선물 컨트롤러의 "새로운"경로의 클립 링크를 아마존 S3 링크로 변환한다는 사실과 관련이 있다고 생각합니다.Paperclip 및 Amazon API를 사용하여 S3에 저장하려고 시도했습니다.
class GiftsController < ApplicationController
skip_before_action :verify_authenticity_token
before_action :amazon_url, only: [:new, :new_extension]
before_action :authenticate_user!
def new
@friend = Friend.find_by_id(params[:id])
if @gift_data.failure == nil
@gift = Gift.new(
name: @gift_data.name,
image: @gift_data.image,
price: @gift_data.price
)
else
@gift = Gift.new()
if params[:search]
@failure = @gift_data.failure
respond_to do |format|
format.html
format.json { render :json => {gift: @gift} }
end
end
end
end
내 선물 모델 : 내가 링크를 URI.parse하기 위해 선물 모델의 방법을 추가하는 시도했지만 한
class Gift < ActiveRecord::Base
belongs_to :category
has_many :ideas
has_many :friends, :through => :ideas
# this friends association doesn't work, need to troubleshoot more or figure that out
# also figure out whether we need it
has_many :goods
has_attached_file :image,
:storage => :s3,
:styles => { :medium => "370x370", :thumb => "100x100" }
validates_attachment_content_type :image, :content_type => /\Aimage\/.*\Z/
validates_presence_of :name
# validates_presence_of :category_id
# validates :url, :url => {:allow_blank => false}
# validates :price, presence: true, format: {with: /\A\d+(?:\.\d{0,2})?\z/}, numericality: {greater_than: 0, less_than: 1000000}
end
가 작동하지 않습니다 는 여기에 몇 가지 코드입니다. 심지어 이미지의 선물 컨트롤러에서 그것을 시도했지만 그 중 하나를 작동하지 않았다. 저는 클립이 아직 만들어지지 않았을 때도 클립을 처리 중이며 이후에 선물을 만들지 못하게한다고 가정합니다. 어떤 지침을 감사하겠습니다!
흠, 나는 어쩌면 누락되었지만 어디에서 @gift를 구할 수 있습니까? 당신이 그것을 만듭니다. 하지만 어디에서 구할 수 있습니까? .save (Gift.new (params) .save)를 추가해야합니다. – denys281
새 경로가 아직 저장하지 않았습니다. 나는 그것을하는 방법을 만든다. – LeChiffre