paperclip

Error: Validation failed: Images imageable must exist , rails-5.0 , paperclip-5

ぐ巨炮叔叔 提交于 2019-12-03 06:19:59
While i was trying to submit the form, following error occured: Validation failed: Images imageable must exist and render the same new.html.erb view. If i comment the file field in new.html.erb . Product is being created successfully. ProductsController: def new @product = Product.new end def create @product = Product.create!(product_params) if @product.save redirect_to products_path, notice: "Product Created Successfully" else render "new" end end def product_params params.require(:product).permit(:name, :quantity, :price, images_attributes: [:id, :photo, :_destroy]) end new.html.erb: <%=

How to do Rails migration involving Paperclip

╄→гoц情女王★ 提交于 2019-12-03 06:07:57
How do people write their Rails migrations that involve Paperclip ? I feel that I might be missing something obvious as I have now written my own migration helpers hacks that makes it easier and also take care of doing necessary filesystem changes. And of course you should test run these kinds of migrations in a development (and staging) environment before deploying to production. Paperclip migration rename, add and remove helpers Paperclip change path migration helper (not really a database migration but think it fits quite nice anyway) Are there any better solutions or best practices? some

How can I restrict Paperclip to only accept images?

无人久伴 提交于 2019-12-03 05:35:34
How can I restrict Paperclip to only accept images? I'm using Amazon S3 for storage if that's relevant. Thanks for reading. Paperclip has validation methods like validates_attachment_presence , validates_attachment_content_type , and validates_attachment_size . So all you need to do is pass mime types of images you'd like to have as attachments: validates_attachment_content_type 'image/png', 'image/jpg' From https://makandracards.com/makandra/606-only-allow-pictures-as-paperclip-attachments validates_attachment_content_type :image, :content_type => /^image\/(jpg|jpeg|pjpeg|png|x-png|gif)$/,

Zip up all Paperclip attachments stored on S3

血红的双手。 提交于 2019-12-03 05:18:46
Paperclip is a great upload plugin for Rails. Storing uploads on the local filesystem or Amazon S3 seems to work well. I'd just assume store files on the localhost, but the use of S3 is required for this app as it will be hosted on Heroku. How would I go about getting all of my uploads/attachments from S3 in a single zipped download? Getting a zip of files from the local filesystem seems straight forward. It's getting the files from S3 that has me puzzled. I think it may have something to do with the way that rubyzip handles files referenced by URL. I've tried various approaches but can't seem

Custom thumbnails for file types with Paperclip

那年仲夏 提交于 2019-12-03 05:11:45
问题 I'm using Paperclip with a Ruby on Rails to attach assets to a model, these assets can be any file type and currently thumbnails are only being generated if the asset is an image. I'd like to be able to display a different default image for other files, either by generating a thumbnail of the files on upload, or setting something up with the default_url but so far I can't find any resources to help with this and am getting no where on my own. My model is as follows: class Asset < ActiveRecord

uploading a file to Rails JSON API server with Paperclip and Multipart request

核能气质少年 提交于 2019-12-03 05:11:23
问题 I want to upload a file from an Android client to a Rails JSON API server. I'm sending a Multipart/form request from the Android client which looks like that: Content-Type: multipart/form-data; boundary=d99ArGa2SaAsrXaGL_AdkNlmGn2wuflo5 Host: 10.0.2.2:3000 Connection: Keep-Alive User-Agent: Apache-HttpClient/UNAVAILABLE (java 1.4) --d99ArGa2SaAsrXaGL_AdkNlmGn2wuflo5 Content-Disposition: form-data; name="POSTDATA" Content-Type: application/json; charset=UTF-8 Content-Transfer-Encoding: 8bit {

Ruby on Rails, Paperclip, Heroku, GitHub and AWS - securing keys

狂风中的少年 提交于 2019-12-03 04:30:43
问题 I'm using RoR hosted by Heroku and I'd like to store files on s3 using paperclip. My source code is hosted on github and is world readable. What is the best practice to keep the keys a secret from the rest of the world? Paperclip suggests that the access keys are stored in a configuration file (or in code), so for example I have: file: config/s3.yml access_key_id: my_access_key_id secret_access_key: my_very_secret_key bucket: bucket_name Heroku works by committing code to local git and then

unit test in rails - model with paperclip

北城余情 提交于 2019-12-03 04:09:53
问题 I'm trying to write a test for a model with a picture, using paperclip. I'm using the test framework default, no shoulda or rspec. In this context, how should I test it? Should I really upload a file? How should I add a file to the fixture? 回答1: Adding file to a model is dead simple. For example: @post = Post.new @post.attachment = File.new("test/fixtures/sample_file.png") # Replace attachment= with the name of your paperclip attachment In that case you should put the file into your test

Generating Paperclip image uploads with fake data - Ruby on Rails Populator / Faker Gems

霸气de小男生 提交于 2019-12-03 03:47:33
问题 I am currently trying to populate a development database on a project with a bunch of fake data, to simulate how it will look and operate with hundreds of articles / users. I looked into different gems to do the task - such as Factory Girl, but documentation was very lacking and I didn't get it - but ended up using the Populator and Faker gems and did the following rake task... namespace :db do desc "Testing populator" task :populate => :environment do require "populator" require "faker" User

Download file on click - Ruby on Rails

别来无恙 提交于 2019-12-03 03:33:23
My application is using Rails 2 backend, Heroku for hosting, Paperclip for file uploads, and Amazon S3 for file storage. Right now users can upload files with paperclip + s3 - this works flawlessly. After upload, an icon appears on their dashboard, linked to the file location (in s3 bucket). When the icon is clicked, the browser opens the file in a new window (for most file types - PDF, MP3, img, etc). Instead of opening, I want the file to be automatically downloaded when the user clicks the file's icon (like Gmail attachments). The solution should be able to work for any file type and cross