paperclip

Paperclip fetch image directly via url

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 13:11:15
It's it possible to fetch an image via url using PaperClip ? It's possible with fleximage, but fleximage has no support for Rails3 so I've switched over to paperclip. At present, I'm fetching the image via curl, saving it on the hdd and load it via image_file of paperclip. I've found no real solution via google, so hopefully you can help me. Yes this is possible and amazingly simple. In your model: #we use this to get the image. require 'rest-open-uri' Class Model << ActiveRecord::Base has_attached_file :picture #Get the picture from a given url. def picture_from_url(url) self.picture = open

Paperclip - rename file before saving

六眼飞鱼酱① 提交于 2019-11-30 11:48:43
问题 I use this method for renaming the image before the saving: def rename_avatar self.avatar.instance_write :file_name, Time.now.to_i.to_s end before_post_process :rename_avatar The image is renamed by the current time, but there's not added the file type, instead of 1334487964.jpg is saved only 1334487964. . What I missing there? I thought :file_name contains only the file name - without the file type 回答1: This is the way how I fix my issue: def rename_avatar #avatar_file_name - important is

Set path for original images using paperclip in Rails?

江枫思渺然 提交于 2019-11-30 11:09:42
问题 The situation I have a simple model with an attached image using paperclip, which has a couple of processed styles for it (thumbnail, full, feature). At this point it works as it should, and makes a directory structure for each object in /public/assets/foo/ , containing subdirectories for original, thumbnail, full, and feature. The problem I don't want the original (high resolution) images to be exposed for users to obtain. So I'm hoping there is a way to specify a different path to store the

Rails file upload (paperclip) on edit

浪子不回头ぞ 提交于 2019-11-30 11:06:12
I made myself a simple rails blogging-type app where I use Paperclip to upload image files.I have everything working fine and dandy. I even have it hooked up to an S3 bucket, etc. Spiffy right? But I can't figure what to do when EDITING/UPDATING a post. As is stands now, all I have is this field on my form template: = f.file_field :image So, say on "post/5/edit" even if there's a previously attached image, the field displays "No file chosen". Even worse, there's no apparent way to clear out current image if I change my mind and don't want to attach an image. How do I make this a little more

Heroku: Running imagemagick with paperclip

丶灬走出姿态 提交于 2019-11-30 11:04:00
问题 I have installed image magick on my mac os x computer and now I want to deploy it to heroku. I've installed the the paperclip plugin on heroku but I get this error when uploading an image: Paperclip::CommandNotFoundError I had this error before when I didn't have imagemagick instaledl on my computer before but now that I want to deploy it, how do I get image magick to work on heroku? 回答1: Do you have the RMagick gem included in your app on Heroku? It's necessary for interfacing between your

How to upload image, word docs and/or PDF files via Paperclip rails 4

妖精的绣舞 提交于 2019-11-30 10:48:51
问题 I would like to enable users to upload Word Docs and PDF files to my rails application. My app is similar to a Pinterest app, users can create Pins where they attach a picture followed by a description (used Paperclip to attach the image to the Pin ). Here is my Pins model: class Pin < ActiveRecord::Base belongs_to :user has_attached_file :image, :styles => { :medium => "300x300>", :thumb => "100x100>" } validates_attachment :image, content_type: { content_type: ["image/jpg", "image/jpeg",

Rails Paperclip Plugin - Style Options for Resizing

点点圈 提交于 2019-11-30 10:36:40
问题 So, I want to resize images to a FIXED width, but proportional height. I have been trying a wide range of operators: 380x242# 380x242> 380!x242 380x242< none of them have the desired effect. Any help? I want it to fill or resize to the 380 width, then resize / shrink the height by the same factor it used to shrink or resize the image to 380 wide. 回答1: Try using 380x This should resize width to 380px and keep original aspect ratio. For all available options for resizing images go here: http:/

Rails 4 multiple file attachments with Paperclip

末鹿安然 提交于 2019-11-30 10:13:05
I'm aware that there are several posts on Stackoverflow and several tutorials about this subject. None of them however manage to solve my issue and most of them are outdated as well. I am trying to add multiple images to a project using the paperclip gem in Rails 4. When i try uploading it i do see the asset attached in the params. They do not seem to be added to the project_paramns though.. Hope someone can help me out here. This is my projects_controller class ProjectsController < ApplicationController before_filter :find_project, only: [:show, :edit, :update, :destroy] def index @projects =

Nested form using paperclip

强颜欢笑 提交于 2019-11-30 09:55:59
I have a model called posts, and it has many attachments. The attachments model is using paperclip. I made a standalone model for creating attachments which works just fine, this is the view as instructed here (https://github.com/thoughtbot/paperclip): <% form_for :attachment, @attachment, :url => @attachment, :html => { :multipart => true } do |form| %> <%= form.file_field :pclip %> <%= form.submit %> <% end %> The nested form in posts looks like this: <% @attachment = @posts.attachments.build %> <%= form_for(@posts) do |f| %> <% if @posts.errors.any? %> <div id="error_explanation"> <h2><%=

Use paperclip for saving base64 images obtained from an api

社会主义新天地 提交于 2019-11-30 08:58:57
I have a Photo model with an image attribute. The image contains a base64 string obtained from an api. I need to run an after_create callback and I was thinking I could use Paperclip for saving the image to the disk in the callback as it would save me some work implementing the folder structure in the public folder and generating thumbnails. Is there an easy way to do that? To answer my own question, here is what I've come up with: class Photo < ActiveRecord::Base before_validation :set_image has_attached_file :image, styles: { thumb: "x100>" } validates_attachment :image, presence: true,