Skip to content

Instantly share code, notes, and snippets.

@rrouse
Created July 4, 2010 15:28
Show Gist options
  • Save rrouse/463524 to your computer and use it in GitHub Desktop.
Save rrouse/463524 to your computer and use it in GitHub Desktop.
padrino g project dniftest -d activerecord -b
create
create config/apps.rb
create config/boot.rb
create config.ru
create public/favicon.ico
create app
create app/app.rb
create app/controllers
create app/helpers
create .components
create Gemfile
Applying 'activerecord' (orm)...
apply orms/activerecord
inject Gemfile
inject Gemfile
create config/database.rb
create app/models
Skipping generator for test component...
Skipping generator for mock component...
Skipping generator for script component...
Applying 'haml' (renderer)...
apply renderers/haml
inject Gemfile
Skipping generator for stylesheet component...
Bundling application dependencies using bundler...
run bundle install from "./"
Project 'dniftest' has been generated and all dependencies bundled!
class CreateStories < ActiveRecord::Migration
def self.up
create_table :stories do |t|
t.string :author
t.string :title
t.text :body
t.datetime :published
t.boolean :draft
end
end
def self.down
drop_table :stories
end
end
rake dnif:configure
rake dnif:index
rake dnif:start
##Search Results
padrino console
=> Loading development console (Padrino v.0.9.14)
=> Loading Application Dniftest
ruby-1.9.2-rc1 > Story.search("teapot")
DEBUG - [04/Jul/2010 14:17:52] "Story Load (0.3ms) SELECT * FROM "stories" WHERE ("stories"."id" IN (1)) "
=> [#<Story id: 1, author: "Robert Rouse", title: "Test Story", body: "I am a teapot, short and stout", published: "2010-07-04 10:39:49", draft: false>]
ruby-1.9.2-rc1 > Story.search("Story")
DEBUG - [04/Jul/2010 14:18:07] "Story Load (0.2ms) SELECT * FROM "stories" WHERE ("stories"."id" IN (1)) "
=> [#<Story id: 1, author: "Robert Rouse", title: "Test Story", body: "I am a teapot, short and stout", published: "2010-07-04 10:39:49", draft: false>]
source :rubygems
# Project requirements
gem 'rake'
gem 'rack-flash'
gem 'thin' # or mongrel
# Component requirements
gem 'haml'
gem 'activerecord', :require => "active_record"
gem 'sqlite3-ruby', :require => "sqlite3"
gem 'dnif'
# Test requirements
# Padrino
gem 'padrino', "0.9.14"
padrino g model Story
=> Located unlocked Gemfile for development
apply orms/activerecord
create app/models/story.rb
create db/migrate/001_create_stories.rb
padrino rake ar:migrate
=> Executing Rake ar:migrate ...
== CreateStories: migrating ==================================================
-- create_table("stories", {})
-> 0.0011s
== CreateStories: migrated (0.0015s) =========================================
gem install padrino
gem install dnif --pre
require 'dnif/tasks'
Dnif.models_path = "./app/models"
task :environment do
require './config/boot'
end
ruby-1.9.2-rc1 > s = Story.new
=> #<Story id: nil, author: nil, title: nil, body: nil, published: nil, draft: nil>
ruby-1.9.2-rc1 > s.author = "Robert Rouse"
=> "Robert Rouse"
ruby-1.9.2-rc1 > s.title = "Test Story"
=> "Test Story"
ruby-1.9.2-rc1 > s.body = "I am a teapot, short and stout"
=> "I am a teapot, short and stout"
ruby-1.9.2-rc1 > s.published = Time.now
=> 2010-07-04 10:39:49 -0500
ruby-1.9.2-rc1 > s.draft = false
=> false
ruby-1.9.2-rc1 > s.save
DEBUG - [04/Jul/2010 10:40:00] "Story Create (0.4ms) INSERT INTO "stories" ("author", "title", "body", "published", "draft") VALUES('Robert Rouse', 'Test Story', 'I am a teapot, short and stout', '2010-07-04 10:39:49', 'f')"
=> true
ruby-1.9.2-rc1 > s = Story.new
=> #<Story id: nil, author: nil, title: nil, body: nil, published: nil, draft: nil>
ruby-1.9.2-rc1 > s.author = "Robert Rouse"
=> "Robert Rouse"
ruby-1.9.2-rc1 > s.title = "Test Story 2"
=> "Test Story 2"
ruby-1.9.2-rc1 > s.body = "Bozz and Witty avoid the Test store"
=> "Bozz and Witty avoid the Test store"
ruby-1.9.2-rc1 > s.published = Time.now
=> 2010-07-04 10:41:09 -0500
ruby-1.9.2-rc1 > s.draft = true
=> true
ruby-1.9.2-rc1 > s.save
DEBUG - [04/Jul/2010 10:41:15] "Story Create (0.3ms) INSERT INTO "stories" ("author", "title", "body", "published", "draft") VALUES('Robert Rouse', 'Test Story 2', 'Bozz and Witty avoid the Test store', '2010-07-04 10:41:09', 't')"
=> true
class Story < ActiveRecord::Base
define_index do
field :title
field :body
where ["draft = ?", false]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment