This gist will collects all issues we solved with Rails 5.2 and Webpacker
# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test
{ | |
"compilerOptions": { | |
/* Basic Options */ | |
"target": "esnext" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */, | |
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */, | |
"lib": [ | |
"esnext", | |
"dom" | |
] /* Specify library files to be included in the compilation. */, | |
// "allowJs": true, /* Allow javascript files to be compiled. */ |
require "rspec/expectations" | |
RSpec::Matchers.define :allow_content_type do |*content_types| | |
match do |record| | |
matcher.matches?(record, content_types) | |
end | |
chain :for do |attr_name| | |
matcher.for(attr_name) | |
end |
This gist will collects all issues we solved with Rails 5.2 and Webpacker
# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test
module ImagesHelper | |
# Outputs html img tag with srcset attribute for 2x image based on original | |
# src. Use naming convention ex. having 'image.jpg', 2x image should be named | |
# '[email protected]'. If there's no image.jpg or [email protected] exception will be | |
# thrown by Rails asset pipeline. | |
def retina_image(src, options = {}) | |
src2x = src.gsub(/(^.+)(\.(jpg|png)$)/, '\1@2x\2') | |
image_tag src, options.merge(srcset: "#{image_url(src2x)} 2x") | |
end | |
end |
<%= form_for(@user) do |f| %> | |
<% if @user.errors.any? %> | |
<div id="error_explanation"> | |
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this user from being saved:</h2> | |
<ul> | |
<% @user.errors.full_messages.each do |msg| %> | |
<li><%= msg %></li> | |
<% end %> | |
</ul> |
# https://github.com/gzigzigzeo/carrierwave-meta | |
# Integrating CarrierWave with JCrop | |
# Let implement the behavior like at this demo: deepliquid.com/projects/Jcrop/demos.php?demo=thumbnail | |
# The uploader: | |
class CropUploader < SobakaUploader | |
include CarrierWave::Meta | |
# Crop source is a source image converted from original which could be bigger than source area (left image in the example). | |
version :crop_source do |
#!/bin/bash | |
# CONF | |
DBG=true | |
[email protected] | |
RELOG_PASSW=xxxxxxxxxxxxxxx | |
# END CONF |
# NullStorage provider for CarrierWave for use in tests. Doesn't actually | |
# upload or store files but allows test to pass as if files were stored and | |
# the use of fixtures. | |
class NullStorage | |
attr_reader :uploader | |
def initialize(uploader) | |
@uploader = uploader | |
end |
module ImagesHelper | |
# Acts as a thin wrapper for image_tag and generates an srcset attribute for regular image tags | |
# for usage with responsive images polyfills like picturefill.js, supports asset pipeline path helpers. | |
# | |
# image_set_tag 'pic_1980.jpg', { 'pic_640.jpg' => '640w', 'pic_1024.jpg' => '1024w', 'pic_1980.jpg' => '1980w' }, sizes: '100vw', class: 'my-image' | |
# | |
# => <img src="/assets/ants_1980.jpg" srcset="/assets/pic_640.jpg 640w, /assets/pic_1024.jpg 1024w, /assets/pic_1980.jpg 1980w" sizes="100vw" class="my-image"> | |
# | |
def image_set_tag(source, srcset = {}, options = {}) | |
srcset = srcset.map { |src, size| "#{path_to_image(src)} #{size}" }.join(', ') |
""" | |
You'll most likely notice you have a something.db-journal file - that was my first sign! | |
I ended up writing a class to abstract stuff away but the key line is, when creating the table, execute the pragma line: | |
PRAGMA journal_mode = OFF | |
http://www.stevemcarthur.co.uk/blog/post/some-kind-of-disk-io-error-occurred-sqlite/ and for more information see here http://www.sqlite.org/pragma.html | |
I found this was due to weird permissions with the default DELETE option. TRUNCATE works as well as OFF |