Skip to content

Instantly share code, notes, and snippets.

View marcoslebron's full-sized avatar
🖐️

Marcos Lebron marcoslebron

🖐️
View GitHub Profile
def outstanding_totals
Invoice.with_state(:sent).to_a.sum(&:total_cents)
end
def drafted_totals
Invoice.with_state(:drafted).to_a.sum(&:total_cents)
end
def paid_totals
Invoice.with_state(:paid).to_a.sum(&:total_cents)
@companies = Company.includes(:company_users).search(params[:q]).page(params[:page]).per(params[:per_page]||6)
@marcoslebron
marcoslebron / capybara_form_submit.rb
Last active May 7, 2020 11:30
I was trying to submit a form without button using just Capybara and Rspec
class Capybara::Session
def submit(element)
Capybara::RackTest::Form.new(driver, element.native).submit({})
end
end
#in the test
fill_in 'Search', with: 'dice'
form = find '#search-form' # find the form
@marcoslebron
marcoslebron / gist:8bdff6fbeffbb8e3f689fb15b250c0ac
Created May 18, 2017 14:18 — forked from stevenringo/gist:1077311
Has Many through factory with fabricator
class Country < ActiveRecord::Base
has_many :registrations
has_many :members
has_many :distribution_groups, :through => :members
end
class DistributionGroup < ActiveRecord::Base
has_many :members
has_many :countries, :through => :members
end
@marcoslebron
marcoslebron / truncate.slim
Created May 19, 2017 19:08
Truncate text
#hellow
hellow
#hellow
width: 10px
white-space: nowrap
overflow: hidden
text-overflow: ellipsis
[1] Time.now + 10.days
[2] 10.days.from_now
[3] -10.days.ago
[4] DateTime.now.days_ago(-10)
[5] Date.today + 10
@marcoslebron
marcoslebron / open_link.js
Created July 12, 2017 18:48
opening link from select option
@marcoslebron
marcoslebron / rails_bootstrap_delete_confirmation_modal.md
Created August 2, 2017 14:22 — forked from postpostmodern/rails_bootstrap_delete_confirmation_modal.md
A nice delete confirmation modal in Rails courtesy of Bootstrap

Here's what you get.

Some CoffeeScript (verbosely commented for clarity)

# Override Rails handling of confirmation

$.rails.allowAction = (element) ->
  # The message is something like "Are you sure?"
  message = element.data('confirm')
======= Prolbem =================================================================================================================
I have installed : ruby-2.0.0,postgres-9.2 , now in rails app when I execute:
rake db:create , command I get:
PG::InvalidParameterValue: ERROR: new encoding (UTF8) is incompatible with the encoding of the template database (SQL_ASCII)
HINT: Use the same encoding as in the template database, or use template0 as template.
: CREATE DATABASE "my_db_name" ENCODING = 'unicode'.......
bin/rake:16:in `load'
@marcoslebron
marcoslebron / 1 Gist conventions
Created December 1, 2017 04:17 — forked from PavloBezpalov/1 Gist conventions
Deploy Rails 5.0.0.beta3 to VPS(Ubuntu 14.04.4 LTS). Nginx, Puma, Capistrano3, PostgreSQL, RVM.
<<APP>> change this variables