Skip to content

Instantly share code, notes, and snippets.

View sahidursuman's full-sized avatar

Sahidur Rahman Suman sahidursuman

View GitHub Profile
def field_with_errors(object, method, &block)
if block_given?
if object.errors[method].empty?
content = with_output_buffer(&block)
content.html_safe
else
content = with_output_buffer(&block)
content_tag(:span, content, :class => "field_with_errors")
end
end
@sahidursuman
sahidursuman / index.md
Last active August 29, 2015 14:20 — forked from rstacruz/index.md

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

#
# At CoverHound, we use conditional validations all over the form. However, there is no proper way to do
# this in Rails. Instead, we can provide an array of attributes (validated_fields attribute)
# and ensure they are the only ones to get validated.
#
module ConditionalValidations
attr_accessor :validated_fields
def field_is_required?(field)
class CreateAuthentications < ActiveRecord::Migration
def change
create_table :authentications do |t|
t.integer :user_id
t.string :provider
t.string :uid
t.string :name
t.string :oauth_token
t.datetime :oauth_expires_at
@sahidursuman
sahidursuman / gist:d7bda162ef511e9cbf9a
Created October 25, 2015 17:11 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
[~/.js] cat github.com.js
// Hashtagify emoji
$(function() {
$('img.emoji').each(function() {
var name = $(this).attr("title").replace(/:/g, '')
if (name == '+1') { name = "thumbsup" }
if (name == '-1') { name = "thumbsdown" }
hashtag = $("<span>#" + name + "</span>");
hashtag.css({ color: '#000', fontWeight: 'bold' });
$(this).replaceWith(hashtag)
@sahidursuman
sahidursuman / .gitattributes
Created October 26, 2015 06:52 — forked from tpope/.gitattributes
Fewer conflicts in your Rails apps
Gemfile.lock merge=bundlelock
db/schema.rb merge=railsschema
@sahidursuman
sahidursuman / gist:5c3bb2d36e3b5ad524d3
Created January 30, 2016 18:05 — forked from agustinvinao/gist:8546440
OpenDataMDP AngularJS providers app
'use strict';
angular.module("providersApp", ["providersApp.services", "providersApp.filters", "providersApp.controllers", "ngResource", "ngRoute", "domstorage"])
.config(["$routeProvider", "$httpProvider", function($routeProvider, $httpProvider) {
$routeProvider.when("/", {
templateUrl: "/angular/views/providers/index.angular.html",
controller: 'ProvidersCntl'
});
$routeProvider.when("/details/:slug", {
templateUrl: "/angular/views/providers/details.angular.html",
@sahidursuman
sahidursuman / git-fame.sh
Created July 29, 2016 16:45 — forked from koffeinfrei/git-fame.sh
git relevant contributors
#!/bin/sh
# Help output
help() {
echo "Usage: git-fame [options] <repository_path>"
echo " -m Machine readable output"
echo " -h Print this help"
exit 1
}