( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
( Source: the mongoid cheatsheet )
class User
include Mongoid::Document
#Model | |
@user.should have(1).error_on(:username) # Checks whether there is an error in username | |
@user.errors[:username].should include("can't be blank") # check for the error message | |
#Rendering | |
response.should render_template(:index) | |
#Redirecting | |
response.should redirect_to(movies_path) |
class Hash | |
def times_with_utc | |
dup.tap do |new_hash| | |
each_key do |key| | |
value = self[key] | |
if value.is_a?(ActiveSupport::TimeWithZone) | |
new_hash[key] = value.utc | |
end | |
end | |
end |
class Hash | |
def times_with_utc | |
dup.tap do |new_hash| | |
each_key do |key| | |
value = self[key] | |
if ActiveSupport::TimeWithZone === value | |
new_hash[key] = value.utc | |
elsif Array === value || Hash === value | |
new_hash[key] = value.times_with_utc | |
end |
require 'ruote' | |
dboard = Ruote::Dashboard.new(Ruote::Worker.new(Ruote::HashStorage.new)) | |
dboard.register_participant 'toto' do |workitem| | |
p [ :pa, workitem.participant_name, workitem.wfid ] | |
end | |
class Listener | |
def initialize(context, opts={}) |
We create an index with:
synonyms_expand
and synonyms_contract
synonyms_expand
and synonyms_contract
text_1
uses the synonyms_expand
analyzer at index and search timetext_2
uses the synonyms_expand
analyzer at index time, but the standard
analyzer at search timetext_3
uses the synonyms_contract
analyzer at index and search time.
module Mongoid | |
module Serialization | |
def serializable_hash_with_id(options = nil) | |
json = serializable_hash_without_id options | |
json['id'] = json['_id'] if json.has_key? '_id' | |
json | |
end | |
alias_method_chain :serializable_hash, :id | |
end | |
end |
#Dev Tools & Resources
##Web-API Development