Skip to content

Instantly share code, notes, and snippets.

@StanBoyet
StanBoyet / user_related_policy.rb
Created September 17, 2014 14:41
User related typical policy
@StanBoyet
StanBoyet / modal.slim.html
Created September 8, 2014 09:46
Boostrap Modal in Slim
/ Simple Slim translation of Bootstrap modal
.modal.fade.bs-example-modal-lg id="myModal" tabindex='-1' role='dialog' aria-labelledby="Modal Title" aria-hidden='true'
.modal-dialog.modal-lg
.modal-content
.modal-header
button.close type='button' data-dismiss='modal'
span aria-hidden='true' ×
span.sr-only Close
h4.modal-title = "Modal Title"
@StanBoyet
StanBoyet / erb2slim_convert_all_views
Last active August 29, 2015 14:05
Using erb2slim for *.erb in your view folder
gem install 'html2slim'
for file in app/views/**/*.erb; do erb2slim $file ${file%erb}slim && rm $file; done
@StanBoyet
StanBoyet / heroku-test.sh
Created May 10, 2014 13:33
Precompile assets for heroku deployment
#!/bin/bash
echo 'Script start'
read -p "Precompile & Push on Test ? (y/n)?"
[ "$REPLY" == "y" ] || RAILS_ENV=production bundle exec rake assets:precompile; git add public/assets; git commit -m "vendor compiled assets"; git push heroku-test master
@StanBoyet
StanBoyet / nil_view.rb
Created March 20, 2014 16:34
Deal with nil variables in view
<% if @messages.each do |message| %>
<%# code or partial to display the message %>
<% end.empty? %>
You have no messages.
<% end %>
@StanBoyet
StanBoyet / generation.rb
Created February 23, 2014 11:40
Generate form, helper etc for model
require 'rubygems'
require 'active_support/core_ext'
schema = File.read('db/schema.rb')
schema.scan(/create_table "(\w+)",.*?\n(.*?)\n end/m).each do |name, ddl|
puts "rails generate scaffold #{name.classify} " +
ddl.scan(/t\.(\w+)\s+"(\w+)"/).
reject {|type,name| %w(created_at updated_at).include? name}.
map {|type,name| "#{name}:#{type}"}.join(' ')
end
# RSpec's subject method, both implicitly and explicitly set, is useful for
# declaratively setting up the context of the object under test. If you provide a
# class for your describe block, subject will implicitly be set to a new instance
# of this class (with no arguments passed to the constructor). If you want
# something more complex done, such as setting arguments, you can use the
# explicit subject setter, which takes a block.
describe Person do
context "born 19 years ago" do
subject { Person.new(:birthdate => 19.years.ago }
it { should be_eligible_to_vote }