Skip to content

Instantly share code, notes, and snippets.

View HK49's full-sized avatar

Taras HK49

  • Kyiv, Ukraine
View GitHub Profile
@HK49
HK49 / Guardfile
Created February 18, 2017 16:43
exemplary guardfile
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
@HK49
HK49 / _error_messages.html.erb
Last active February 18, 2017 17:08
Initializer to override default field with errors (rails 5.0.1)
<!-- path: views/layouts/ -->
<% if object.errors.any? %>
<% object.errors.full_messages.each do |msg| %>
<%=
content_tag :div, :id => "has_errors", :style => "padding:3px; margin:0 20vw; background-color:rgba(246, 138, 138, 0.7); border:solid rgba(246, 138, 138, 1) 1px; border-radius:12px; text-align:center;" do
concat(content_tag :p, msg)
end
-%>
<% end %>
@HK49
HK49 / _form.html.erb
Last active February 10, 2017 11:43
Update action for Carrierwave 1.0 Multifile upload with single controller (delete several files or delete all)
<%= content_tag :div, :class => "gallery_rows" do -%>
<% gallery.photo.each do |image| %>
<%= content_tag :div, :class => "gallery_image", :id => "gallery_image_#{gallery.photo.index(image)+1}" do -%><%# delete by index %>
<%= content_tag :div, :class => "imagethumb" do -%>
<%= image_tag(image.thumb.url) if gallery.photo? -%>
<% end %>
<p>Delete photo?</p>
<div class="imageswitch">
<%= check_box_tag 'delete_this_images[]', gallery.photo.index(image),
false, id: "delete_image_#{gallery.photo.index(image)+1}", class: 'imageswitch-cb'
@HK49
HK49 / server.rake
Last active July 7, 2017 14:02
Simple Rake task for launching Puma server with Postgresql and Guard.
def puma_pidfile # puma pid file path
@puma_pidfile = ENV['PIDFILE'] || "tmp/pids/puma.pid"
end
def puma_port # port where puma runs
@puma_port = ENV['PORT'] || "8080"
end
namespace :guard do