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