This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class << ActiveRecord::Base | |
alias_method :[], :find | |
end | |
@post = Post[5] | |
@post = Post[:first] | |
@post = Post[:all, :conditions => { :name => "first post" }] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=begin | |
notice there is no space at the beginning of =begin | |
code or | |
#comment | |
. | |
. | |
. | |
=end | |
=begin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#config/initializers/omniauth.rb | |
require 'openid/store/filesystem' | |
ActionController::Dispatcher.middleware.use OmniAuth::Builder do #if you are using rails 2.3.x | |
#Rails.application.config.middleware.use OmniAuth::Builder do #comment out the above line and use this if you are using rails 3 | |
provider :twitter, 'key', 'secret' | |
provider :facebook, 'app_id', 'secret' | |
provider :linked_in, 'key', 'secret' | |
provider :open_id, OpenID::Store::Filesystem.new('/tmp') | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
attr_accessor :password_confirmation | |
acts_as_authentic do |c| | |
c.validates_length_of_login_field_options :within=>1..30 #username can be 1 to 30 characters long | |
c.validates_format_of_login_field_options = {:with => /^[a-zA-Z0-9_]+$/, :message => I18n.t('error_messages.login_invalid', :default => "should use only alphabets, numbers and underscores no other characters.")} #username can only contain alphabets, numbers and "_" no other characters permitted | |
#the below two would make password and password_confirmation optional i.e, you don't have to fill it. | |
c.ignore_blank_passwords = true #ignoring passwords | |
c.validate_password_field = false #ignoring validations for password fields | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#app/models/user.rb | |
class User < ActiveRecord::Base | |
has_many :authorizations, :dependent => :destroy | |
end | |
#app/models/authorization.rb | |
class Authorization < ActiveRecord::Base | |
belongs_to :user | |
validates_presence_of :user_id, :uid, :provider | |
validates_uniqueness_of :uid, :scope => :provider |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#/app/models/user.rb | |
class User < ActiveRecord::Base | |
has_many :authorizations, :dependent => :destroy | |
def self.create_from_hash(hash) | |
create(:username => hash['user_info']['name']) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var msie6 = $.browser == 'msie' && $.browser.version < 7; | |
if (!msie6) { | |
// 'bar' is the id of the box which needs to be fixed | |
var top = $('#bar').offset().top - parseFloat($('#bar').css('margin-top').replace(/auto/, 0)); | |
$(window).scroll(function (event) { | |
var y = $(this).scrollTop(); | |
if (y >= top) { | |
// if so, add the fixed class | |
$('#bar').addClass('fixed'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.default-value').each(function() { // '.default-value' is the class for your fields having default values | |
var default_value = this.value; | |
$(this).css('color', '#999'); // this could be in the style sheet instead | |
$(this).focus(function() { | |
if(this.value == default_value) { | |
this.value = ''; | |
$(this).css('color', '#333'); | |
} | |
}); | |
$(this).blur(function() { |
OlderNewer