2016-06-13 2 views
0

나는 특정 웹 페이지를 긁어 내고 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_sizeavatar_updated_atnil 남아 있다는 것입니다 가지고있는 문제 :와 컨트롤러 코드

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 
+0

당신은 우리에게'controller'와'view'를 보여줄 수 있습니까? –

+0

LinksController에서 세부 사항을 추가했습니다. 그러나 당신이 볼 수 있듯이 모든 꽤 표준적인 것들입니다. 웹 페이지를 고치고 링크 모델의 데이터를 저장하는 데 문제가 없습니다. 링크 저장 후 아바타 데이터를 저장하는 데 문제가 있습니다. – BillyBib

+0

또한 데이터를 사용하고 있지 않습니다. 보기에서 – BillyBib

답변

0

나는 그것을 해결했다.

Link은 어떤 종류의 저장 작업으로도 데이터가 보존되지 않았기 때문에 업데이트 된 avatar 정보를 가져 오지 못했습니다. 그래서 내가하는 경우 :

def picture_from_url 
    self.avatar = URI.parse(self.image_url) 
    self.save 
end 

모든 것이 잘 작동합니다. 내 모델에 self.save을 호출하는 것에 대한 피드백을 얻는 것이 좋을 것입니다. 그것은 나에게 냄새가 난다.