Trick: Do not use
mogrify -resize 50% *
This overwrites the original image file.
convert writes to a different image file. Here is an example if you need this:
cd /path/to/image/directory for i in `ls -1 *jpg`; do convert -resize 50% $i "thumb_$i"; done
Here is how to make Rome datepicker look like the rest of your Bootstrap 4 application.
Rome comes with very little basic styling. While we could redefine its classes, we can configure the classes Rome applies to its elements to make it look like this:
Since Bootstrap 4 comes with several helpful utility classes, and requires fewer markup/containers, we can achieve Bootstrap 4 experience by applying a few classes via the
You still need to include `ro…
E.g. to make an image cover a 100x100 px² area, cropping the image when nece…
Webpacker is Rails' way of integrating Webpack, and version 4 has been released just a few days ago, allowing us to use Webpack 4.
I successfully upgraded an existing real-world Webpack 3 application. Below are notes on everything that I encountered.
Note that we prefer not using the Rails asset pipeline at all and serving all assets through Webpack for the sake of consistency.
Localizing a non-trivial application can be a huge undertaking. This card will give you an overview over the many components that are affected.
When you are asked to give an estimate for the effort involved, go through the list below and check which points are covered by your requirements. Work with a developer who has done a full-app localization before and assign an hour estimate to each of these points.
appmust be translated: Screens, mailer templates, PDF templates, helpe…
Today's cameras create huge images, some beyond 50MB. Unless you need to offer this large files, you should always shrink uploaded files to a reasonable resolution.
class ImageUploader < CarrierWave::Uploader::Base process resize_to_limit: [3000, 3000] # ... end
processdefinitions are only applied to the original file
after) are applied to original file and each version by itself
#version_name: version uploaders return the version name, whereas the original uploader instance returns
If your Carrierwave uploader dynamically generates the filename (e.g. by incorporating a user's name), you must call
model.save! after recreating versions, because
uploader.recreate_versions! does not update the model with the stored filename.
As your Rails project grows, you will accumulate a number of small patches. These will usually fix a bug in a gem, or add a method to core classes.
Instead of putting many files into
config/initializers, I recommend to group them by gem in
Enumerable.find(&block), which returns the first item in the collection for which the block evaluates to
first_post_with_image = posts.find do |post| post.image end
However, sometimes it's not the item you're interested in, but some value depening on it – e.g. the value the block evaluated to. You could first map the collection and then take the first truthy value, but this way you need to process the whole collection twice:
first_image_url = posts.map(&:image).find(&:present?).url
If the mapping …
Subject: performance on smartphones and tablets
I just used your framework in one project and must say,
I am really pleased with it – but only on a desktop computer.
Have you benchm…
Pour color on your Rails console with awesome_print. Turn confusing long strings into formatted output. Have objects and classes laid out clearly whenever you need it.
gem 'awesome_print', :group => :development into your Gemfile. Now on the Rails console you have the command
ap that will give you a colored, formatted output of whatever you pass it. See the example output of the
User class below.
For customization visit the repository on Github.
Carrierwave includes some handy helper methods you can use to resize your images. Here is a quick summary of them, if you need more details read the docs. You can also use all command line options from RMagick directly if these helpers are not good enough for you.
Set the ruby version in
.ruby-version to 2.3.5, then perform these steps one by one, fixing errors as they occur:
1) Update gems as listed below, and bundle
2) Boot a Rails console - see below for a list of changes you will probably need
3) Run Specs with
4) Run Cucumber features (with Geordi's
5) When all tests are green, look through your Gemfile and remove as many version constraints as possible.
6) Boot the application in different environements to spot further issues, e…
When using virtual attributes, the attached trait can be useful to automatically copy errors from one attribute to another.
Here is a typical use case where Paperclip creates a virtual attribute
:attachment, but there are validations on both
:attachment_file_name. If the form has a file picker on
:attachment, you would like to highlight it with errors from any attribute:
class Note < ActiveRecord::Base has_attached_file :attachment validates_attachment_presenc...
When building a web application, one is tempted to claim it "done" too early. Make sure you check this list.
Desktops, tablets and mobile devices have all different screen resolutions. Does your design work on each of them?
Occasionally, your designer will hand you designs where elements break the layout's horizontal container width, like navigation buttons of a slider that should be at the left/right of the browser window, or simply by applying a background color that reaches until the left and right of the browser window.
In the past, we've done some horrible things to achieve that. Like
margin: 0 -10000px plus
There is a much saner approach.
Consider the following markup: