나는 특정 웹 페이지를 긁어 내고 Link
모델에 데이터를 저장하는 레일 4 응용 프로그램이 있습니다.모델 아님 보관 아바타 데이터
after_save
콜백과 함께 Paperclip gem을 사용하여 이미지의 URL을 가져온 다음 AWS S3에 업로드하고 있습니다. 이 모든 것은 정상적으로 작동하며 S3 버킷의 이미지를 볼 수 있습니다.
나는이 (가) Link
link.rb:
class Link < ActiveRecord::Base
after_save :picture_from_url
has_attached_file :avatar, styles: { medium: "300x300>", thumb: "100x100>" }, default_url: "/images/:style/missing.png"
validates_attachment_content_type :avatar, content_type: /\Aimage\/.*\Z/
...
def picture_from_url
self.avatar = URI.parse(self.image_url)
end
end
UPDATE를 첨부 된 :avatar
이없는 것처럼 데시벨에서 avatar_file_name
, avatar_content_type
, avatar_file_size
및 avatar_updated_at
열 nil
남아 있다는 것입니다 가지고있는 문제 :와 컨트롤러 코드
class LinksController < ApplicationController
...
def new
@link = Link.new
end
def create
@link = Link.create(link_params)
if @link.save
flash[:success] = "Thanks for your submission!"
redirect_to link_path(@link)
else
render :new
end
end
private
def link_params
params.require(:link).permit(:title, :url, :content, :tag_list, :category, :image_url, :avatar).merge(user_id: current_user.id, author_first_name: current_user.first_name)
end
end
당신은 우리에게'controller'와'view'를 보여줄 수 있습니까? –
LinksController에서 세부 사항을 추가했습니다. 그러나 당신이 볼 수 있듯이 모든 꽤 표준적인 것들입니다. 웹 페이지를 고치고 링크 모델의 데이터를 저장하는 데 문제가 없습니다. 링크 저장 후 아바타 데이터를 저장하는 데 문제가 있습니다. – BillyBib
또한 데이터를 사용하고 있지 않습니다. 보기에서 – BillyBib