0
我有一個Rails 4應用程序,它可以擦除給定的網頁並將數據保存在Link
模型中。模型不保存Paperclip頭像數據
我使用Paperclip gem和after_save
回調來獲取圖像的url,然後將其上傳到AWS S3。這一切工作正常,我可以查看我的S3桶中的圖像。
我是在分貝avatar_file_name
,avatar_content_type
,avatar_file_size
和avatar_updated_at
列保持nil
彷彿沒有:avatar
附的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
更新問題:與控制器代碼
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的細節,但是你可以看到它是所有非常標準的東西。我沒有任何麻煩,在保存鏈接後,我無法保存鏈接數據,並且在Link模型中保存數據。 – BillyBib
此外,我目前沒有使用數據在視圖 – BillyBib