Create
Learn
Share

Merb And Datamapper

rename
Updated 2008-05-02 08:10

Summary

Terms and concepts re Merb and DataMapper.

Misc

Question Answer
start servermerb -p 4001 (-p 4001 is optional)
start server using thinmerb -a thin
task to reconstruct dbrake dm:db:automigrate
standard for web server abstraction merb usesrack
getting at the loggerMerb.logger
memorize

 

Question Answer
getting at the environmentMerb.environment
gem to pass request params as method argsmerb-action-args
use a new gemdependency 'merb-action-args' (in init.rb)
generate model, view, and controllermerb-gen resource foo
run merb consolemerb -i
memorize

Controllers / Views

Question Answer
before filterbefore
redirectredirect url(:foo, @foo)
formform_for(:foo, :action => url(:foo)) { ... }
text fieldtext_control(:foo, :label => "Foo")
dropdownselect_control(:foo, :label => "Foo", :collection => @bars)
memorize

 

Question Answer
textareatext_area_control(:foo, :label => "Foo")
submit buttensubmit_button "Food"
link to a pagelink_to "Foo", url(:foo)%>
include css filecss_include_tag
rendering a partialpartial :foo
partssimilar to old rails components - lightweight, useful for sidebars, widgets etc
memorize

Models

Question Answer
generate a modelmerb-gen model foo
validation using lambdavalidates_true_for :foo, :logic => lambda { foo > 0 }
model property with size validationproperty :foo, :string, :length => 255
model property with default valueproperty :foo, :string, :default => 'bar'
find and sortFoo.all :order => 'bar desc'
memorize

 

Question Answer
find first nFoo.all :limit => 10
get number of recordsFoo.count
delete records where bar = 0Foo.each(:bar == 0).each { |c| f.destroy! }
datamapper operatorsgt/lt, gte/lte, not, like, in
find_by_sql retursan array of Structs
memorize