Skip to content

Instantly share code, notes, and snippets.

View tagrudev's full-sized avatar

Todor Grudev tagrudev

View GitHub Profile
@tagrudev
tagrudev / gist:5345691
Last active December 16, 2015 00:09
Singleton for a factory inside another's factory traits = No ideas
FactoryGirl.define do
factory :user do
first_name 'John Doe'
last_name 'Doe'
trait :yolo do
first_name 'Spinder'
last_name 'Man'
end
factory :spinder, traits: [:yolo]
end
<%= form_for(@project) do |f| %>
<% if f.errors.any? %>
<div id='error_explanation'>
<h2><%= pluralize(f.errors.count, 'error') %>
prohibited this foo from being saved:</h2>
<ul>
<% f.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
@tagrudev
tagrudev / gist:5219811
Created March 22, 2013 08:42
get all models Rails
Module.constants.select do |constant_name|
constant = eval constant_name
if not constant.nil? and constant.is_a? Class and constant.superclass == ActiveRecord::Base
constant
end
end
@tagrudev
tagrudev / gist:5208008
Created March 20, 2013 20:10
import csv to your posgre via rails yolo
require 'csv'
namespace :seed do
desc "seed some awesomeness"
task :awesomeness => :environment do
CSV.foreach(File.join(Rails.root, 'lib/assets/yolo.csv')) do |row|
Awesome.create(:attribute_a => row[0], :attribute_b => row[1])
end
end
end
2.0.0dev :015 > raw_params = {"layout"=>"layout_04", "zone_ids"=>["", "", "", "50e5a81a421aa977fa00000b"]}
=> {"layout"=>"layout_04", "zone_ids"=>["", "", "", "50e5a81a421aa977fa00000b"]}
2.0.0dev :016 > params = ActionController::Parameters.new(raw_params) => {"layout"=>"layout_04", "zone_ids"=>["", "", "", "50e5a81a421aa977fa00000b"]}
2.0.0dev :017 > params.permit(:zone_ids => []) => {"zone_ids"=>["", "", "", "50e5a81a421aa977fa00000b"]}
class PerspectivesController < ApplicationController
# GET /perspectives
# GET /perspectives.json
def index
@perspectives = Perspective.all
unless params['perspective']
@perspective = @perspectives.where(default: true).first || Perspective.new
else
@perspective = Perspective.new
end
@tagrudev
tagrudev / Gemfile
Last active December 14, 2015 09:09 — forked from anonymous/Gemfile
source 'http://rubygems.org'
# source 'http://localhost:9292'
gemspec
group :test do
gem "simplecov", :require => false
gem "shoulda-matchers"
gem "shoulda-context"
gem "capybara-screenshot"
@tagrudev
tagrudev / gist:4537658
Created January 15, 2013 10:04
link_to image + text
<%= link_to '#' do %>
hiii <%= image_tag('/images/menu-arrow-down.gif') %>
<% end %>
str = (0...MAX_NUM).map { |n| n.en.numwords }.join.gsub(/ and /, "").gsub(/\W/, "")
NoMethodError: undefined method `en' for 0:Fixnum
@tagrudev
tagrudev / gist:4351631
Last active December 10, 2015 00:29 — forked from anonymous/gist:4351607
def create_report
if @inspection.type == 'RoutineInspection'
puts "---CR> CREATING ROUTINE INSPECTION REPORT"
pdf = routine_inspection_generic
else
puts "---CR> CREATING INGOING INSPECTION REPORT"
thread = Thread.new do
pdf = ingoing_inspection_nsw
end.join
end