Skip to content

Instantly share code, notes, and snippets.

View achiurizo's full-sized avatar
🌞

Arthur Chiu achiurizo

🌞
View GitHub Profile
module DataMapperInitializer
def self.registered(app)
app.configure :production do
DataMapper.setup(:default, 'your_db_here')
end
app.configure :development do
DataMapper.setup(:default, 'your_db_dev_here')
end
app.configure :test do
DataMapper.setup(:default,'your_db_test_here')
project :test => :shoulda, :orm => :activerecord, :dev => true
generate :model, "post title:string body:text"
generate :controller, "posts get:index get:new post:new"
generate :migration, "AddEmailToUser email:string"
generate :fake, "foo bar"
require_dependencies 'nokogiri'
inject_into_file "app/models/post.rb","#Hello", :after => "end\n"
project :test => :shoulda, :renderer => :haml, :stylesheet => :sass, :script => :jquery, :orm => :activerecord
#default routes
APP_INIT = <<-APP
get "/" do
"Hello World!"
end
get :about, :map => '/about_us' do
render :haml, "%p This is a sample blog created to demonstrate the power of Padrino!"
CODERAY = <<-CODERAY
require 'rack/coderay'
app.use Rack::Coderay,
"//pre[@lang]",
:line_numbers => :table
CODERAY
require_dependencies 'coderay', 'rack-coderay'
initializer :coderay,CODERAY
get 'http://coderay.rubychan.de/stylesheets/coderay.css', 'public/stylesheets/coderay.css'
vendor_path = File.dirname(__FILE__) + '/vendor'
# Padrino
%w(core gen helpers mailer admin).each do |gem|
padrino_lib = vendor_path + '/padrino-framework'
gem 'padrino-' + gem, :path => "#{padrino_lib}/padrino-" + gem
end
Admin.controllers :accounts do
get :index do
@accounts = Account.all
render 'accounts/index'
end
get :new do
@account = Account.new
render 'accounts/new'
# /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb in const_missing
#
98. parent.send :const_missing, const_name
99. end
100. rescue NameError => e
101. # Make sure that the name we are missing is the one that caused the error
102. parent_qualified_name = Dependencies.qualified_name_for parent, const_name
103. raise unless e.missing_name? parent_qualified_name
104. qualified_name = Dependencies.qualified_name_for self, const_name
# /Library/Ruby/Gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb in load_missing_constant
#
436. begin
437. return parent.const_missing(const_name)
438. rescue NameError => e
439. raise unless e.missing_name? qualified_name_for(parent, const_name)
440. raise name_error
441. end
442. else
get :new do
you went to "/new"
end
get :new, :with => :id do
"you went to /new/123"
end
class Photo
include Mongoid::Document
include Mongoid::Timestamps # adds created_at and updated_at fields
# fields
field :caption, :type => String
field :tags, :type => Array, :default => []
before_save :make_tags