Skip to content

Instantly share code, notes, and snippets.

:shipit:
aha

DiveInto

:shipit:
aha
Block or report user

Report or block DiveInto

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View where.rb
@unsold = SellInfo.where("user_id = ? and deal_status != 'sold'", current_user.id)
@sold = SellInfo.where("user_id = ? and deal_status = 'sold'")
View scope.rb
class SellInfo < ActiveRecord::Base
belongs_to :book
belongs_to :user
scope :onsale,:conditions => ['deal_status is not "sold"']
scope :saled,:conditions => {:deal_status => "sold"}
end
@DiveInto
DiveInto / mongoOp.scala
Created Apr 6, 2012
mongo ops using scala/java
@DiveInto
DiveInto / condition.rb
Created Apr 4, 2012
condition syntax,shows usage of ? :
View condition.rb
(req.save == nil)? false:true
@DiveInto
DiveInto / flash.rb
Created Apr 4, 2012
how to use flash to notice
View flash.rb
flash[:notice] = "Item successfully saved as your favourite!"
#很奇怪,看官方文档,rails3里应该flash消息应该可以直接用notice(类似: redirect_to :action=>:XXX,:notice => "msg"),但我试了不行,不知为何,所以这儿还是用的老的style,记下备忘。
@DiveInto
DiveInto / add field.rb
Created Mar 30, 2012
add field using rails generate
View add field.rb
rails generate migration add_password_to_users encrypted_password:string
class AddPasswordToUsers < ActiveRecord::Migration
def self.up
add_column :users, :encrypted_password, :string
end
def self.down
remove_column :users, :encrypted_password
end
@DiveInto
DiveInto / add index.rb
Created Mar 26, 2012
how to add index using rails migration
View add index.rb
class AddIndexToFavourites < ActiveRecord::Migration
def self.up
add_index :favourites,[:user_id,:sell_info_id],:unique => true
end
def self.down
remove_index :favourites,[:user_id,:sell_info_id]
end
end
You can’t perform that action at this time.