Skip to content

Instantly share code, notes, and snippets.

View Ademola101's full-sized avatar
🏠
Grinding

Ademola Ogunmokun Ademola101

🏠
Grinding
  • Software Developer
  • Nigeria
  • 13:39 (UTC -12:00)
  • X @ademola_isr
View GitHub Profile
@rayning0
rayning0 / gist:6724800
Last active October 28, 2021 22:29
My_Each method, using Yield
# Read about the yield keyword and ruby blocks.
# http://allaboutruby.wordpress.com/2006/01/20/ruby-blocks-101/
# http://ruby.about.com/od/beginningruby/a/Block-Parameters-And-Yielding.htm
# http://blog.codahale.com/2005/11/24/a-ruby-howto-writing-a-method-that-uses-code-blocks/
# http://www.robertsosinski.com/2008/12/21/understanding-ruby-blocks-procs-and-lambdas/
# Now that you know how the yield method works, try to write your
# own version of the each method without using the each method
# provided by ruby. As in, try to build my_each using only the
@PWSdelta
PWSdelta / rspec_model_testing_template.rb
Last active June 12, 2025 15:08
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@sumitasok
sumitasok / user.rb
Created April 24, 2012 09:35
accepts_nested_attributes_for - Rails association management using single form submit.
# model file
class User < ActiveRecord::Base
has_many :books
accepts_nested_attributes_for :books, :reject_if => lambda {|book| book[:name].blank? }, :allow_destroy => true
end
# :reject_if => it passes the whole hash passed from browser with book details into this Proc(lambda) and iterates over each book hash. The book record is not created if the condition given in the lambda block is satisfied.
# :allow_destroy => if set to true, then the book record that was passed from browser, while submitting User form, with a key-value pair :_destroy => 1 (or '1' or true or "true") will be destroyed
@structuralartistry
structuralartistry / fading_flash_notice_rails
Created December 23, 2010 00:31
Simple fading flash[:notice] in Rails with jQuery
# I struggled with getting a fading flash[:notice] that would work both with standard served pages as well
# as ajax requests. I saw a number of posts online but did not have luck with or they seemed too
# complicated. This is what I ended up with from experimentation.
# Place the following code in application_helper.rb. Note that you need to either change or name your
# containers as I have in this code:
# application_helper.rb
module ApplicationHelper