Tuesday, December 21, 2010
Lunar Eclipse
Tuesday, December 14, 2010
sqlite3-ruby 1.3.2 on Windows 'Error'
When I created a new rails app ran bundle install I noticed a new version of sqlite3-ruby was installed.
...
Installing sqlite3-ruby (1.3.2)
...
When I tried to start the server I got this message.
C:\web\testapp>rails s
C:/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.3.2-x86-mingw32/lib/sqlite3.rb:6:in `require': no such file to load -- sqlite3/sqlite3_native (Load Error)
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.3.2-x86-mingw32/lib/sqlite3.rb:6:in `rescue in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/sqlite3-ruby-1.3.2-x86-mingw32/lib/sqlite3.rb:2:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:64:in `block (2 levels) in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:62:in `block in require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `each'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler/runtime.rb:51:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/bundler-1.0.7/lib/bundler.rb:112:in `require'
from C:/web/testapp/config/application.rb:7:in `<top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `require'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:28:in `block in <top (required)>'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
from C:/Ruby192/lib/ruby/gems/1.9.1/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
I thought I'd reinstall it, since that's what one does on windows, and I got some more information.
C:\web\testapp>gem install sqlite3-ruby
=============================================================================
You've installed the binary version of sqlite3-ruby.
It was built using SQLite3 version 3.7.3.
It's recommended to use the exact same version to avoid potential issues.
At the time of building this gem, the necessary DLL files where available
in the following download:
http://www.sqlite.org/sqlitedll-3_7_3.zip
You can put the sqlite3.dll available in this package in your Ruby bin
directory, for example C:\Ruby\bin
=============================================================================
Successfully installed sqlite3-ruby-1.3.2-x86-mingw32
1 gem installed
Installing ri documentation for sqlite3-ruby-1.3.2-x86-mingw32...
Installing RDoc documentation for sqlite3-ruby-1.3.2-x86-mingw32...
Let's look at what was installed.
C:\web\testapp>gem list --local -d sql
*** LOCAL GEMS ***
sqlite3-ruby (1.3.2)
Platform: x86-mingw32
Authors: Jamis Buck, Luis Lavena, Aaron Patterson
Rubyforge: http://rubyforge.org/projects/sqlite3-ruby
Homepage: http://github.com/luislavena/sqlite3-ruby
Installed at: C:/Ruby192/lib/ruby/gems/1.9.1
This module allows Ruby programs to interface with the SQLite3
database engine (http://www.sqlite.org)
I downloaded the file at http://www.sqlite.org/sqlitedll-3_7_3.zip and copied the DLL into my C:\Ruby192\bin folder since that's where I have it installed.
Let's give it a try
C:\web\testapp>rails s
=> Booting WEBrick
=> Rails 3.0.3 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-12-14 11:37:09] INFO WEBrick 1.3.1
[2010-12-14 11:37:09] INFO ruby 1.9.2 (2010-08-18) [i386-mingw32]
[2010-12-14 11:37:09] INFO WEBrick::HTTPServer#start: pid=2080 port=3000
[2010-12-14 11:37:56] INFO going to shutdown ...
[2010-12-14 11:37:57] INFO WEBrick::HTTPServer#start done.
It works.
Tuesday, November 30, 2010
Make An HTML Version of the iPhone's Contact Screen.
Make An HTML Version of the iPhone's Contact Screen.
We want this, but not so blurry.I'm going to break it down with a heading, text and a list. I'll go with a definition list. We define the phone numbers, email and address.
Let's mark up the base.
<html>
<head>
<meta charset="utf-8" />
<title>Person</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, details, figcaption, figure, footer, header,
hgroup, menu, nav, section { display: block; }
</style>
</head>
<body>
<h2>John Ivanoff</h2>
<p>Some Company</p>
<dl>
<dt>work</dt>
<dd>972-555-1212</dd>
<dt>home</dt>
<dd>972-555-1212</dd>
</dl>
<dl>
<dt>work</dt>
<dd><a href="mailto:unknown@unknown.org">unknown@unknown.org</a></dd>
</dl>
<dl>
<dt>work</dt>
<dd><a href="http://goo.gl/1nTU8">123 Chicago Ave<br/>Lebanon, KS 76051-7693 </a></dd>
</dl>
</body>
</html>
We have the foundation. Now let's add some style.
We'll start with the background of the page.
background-color: #ddd; /* Background color */
color: #222; /* Foreground color used for text */
font-family: Helvetica;
font-size: 14px;
margin: 0; /* Amount of negative space around the outside of the body */
padding: 0; /* Amount of negative space around the inside of the body */
}
Let's get the lists styled.
We'll add the white background and border.
list-style: none;
padding: 0;
}
dt, dd {
background-color: #fff; /* Background color */
color: #222222; /* Foreground color used for text */
border: 1px solid #999;
font-weight: bold;
margin: 0;
padding: 12px 10px;
}
dt:first-child {
-webkit-border-top-left-radius: 8px;
}
dt:first-child + dd { /* This rounds the first definition item */
-webkit-border-top-left-radius: 8px;
-webkit-border-top-right-radius: 8px;
}
dd:last-child {
-webkit-border-bottom-right-radius: 8px;
-webkit-border-bottom-left-radius: 8px;
}
We'll style the 'terms.' We'll make them 60 pixels wide, have the text align to the right and make it a little lighter in color.
color: #516691;
text-align: right;
width: 60px;
}
Now we'll move up the 'definitions' so it looks like one line. We'll float the dt
float: left; /* this will 'bring up' the dd */
color: #516691;
text-align: right;
width: 60px;
}
That doesn't look good. We'll remove the border on the dt and I'm picky here but I want to move the dt a little bit.
float: left; /* this will 'bring up' the dd */
border: 0; /* remove border */
padding-top: 13px; /* alignment tweaking */
color: #516691;
text-align: right;
width: 60px;
}
That's a little better but the top left looks like crud. The remedy? Make the color of the dt transparent.
float: left; /* this will 'bring up' the dd */
border: 0; /* remove border */
padding-top: 13px; /* alignment tweaking */
color: #516691;
text-align: right;
width: 60px;
background-color: transparent; /* clears up the top left corner */
}
Looking good.
Let's work on the name and company. We'll wrap a div around the contact name and company
<div id="namecompany">
<h2>John Ivanoff</h2>
<p>Some Company</p>
</div>
.....
padding-left: 90px; /* Makes room for the photo */
background: transparent url(../i/person-icon.png) 10px 0 no-repeat; /* This sets up the position of the image */
height: 70px; /* Set the height of the div */
}
div#namecompany h2, div#namecompany p {
margin: 0; /* Just smash it all together */
}
We're starting to cook with gas. A few minor areas to touch up. We need padding around the page.
We can hack it and add a margin to the entire page. The problem with that is when we add a header or footer that will ruin the look. The header or footer will not span the width of the screen.
What about wrapping everything in a div content? That add unnecessary HTML.
For this simple layout I'll add the padding to the namecompany div and the lists
margin: 10px;
}
Smashing. Be'll make the phone numbers into links so we can call
<dl>
<dt>work</dt>
<dd><a href="tel:972-555-1212">972-555-1212</a></dd>
<dt>home</dt>
<dd><a href="tel:972-555-1213">972-555-1213</a></dd>
</dl>
...
Let's hide those ugly links.
text-decoration: none;
color: #000;
}
With this current design if you have a really long email the email will wrap just like the address. In the contacts app on the iPhone long emails are truncated with a trailing ellipsis.
We'll add a home email and make it a really long email address and we'll add a class of email to the dd
<dl>
<dt>work</dt>
<dd class="email"><a href="mailto:unknown@unknown.org">unknown@unknown.org</a></dd>
<dt>home</dt>
<dd class="email"><a href="mailto:unknown.unknown@areallyreallyreallylongurl.org"> unknown.unknown@areallyreallyreallylongurl.org</a></dd> </dl>
...
That's not good.
Let's add an ellipsis to text that is too long for its container.
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
Still not good.
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block;
width: inherit;
}
Update…
That code will render like the previous image.Move the .email class into the a element. The a element should look like the following
text-decoration: none;
color: #000;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
display: block;
width: inherit;
}
Then remove the .email class from the <dd> for the emails,
Moving that code to the a element will also insure that any long text will be shortened to stay within the page.
View it in a browser.
Hurray!
Let's add some finishing touches.
A title bar and the pinstriped background. Add this to the html code.
<h1>Info</h1>
...
background: #ddd url(../i/pinstripes.png) repeat scroll 0%;
color: #222; /* Foreground color used for text */
font-family: Helvetica;
font-size: 14px;
margin: 0; /* Amount of negative space around the outside of the body */
padding: 0; /* Amount of negative space around the inside of the body */
}
...
h1 {
color: #222;
font-size: 20px;
font-weight: bold;
margin: 0 auto;
padding: 10px 0;
text-align: center;
text-shadow: 0px 1px 0px #fff;
background-image: -webkit-gradient(linear, left top, left bottom,
from(#ccc), to(#999));
}
There we go, a web page that looks like a native iPhone app.
Thursday, November 18, 2010
rails 3.0.3 and activerecord-sqlserver-adapter (3.0.5) error on windows
Wednesday, September 01, 2010
Ruby 1.9.2 Rails 3, A Clean Install on Windows XP
Down loaded rubyinstaller-1.9.2-p0.exe from http://rubyinstaller.org/ and installed it. (this will remove any previously installed gems)
C:>gem list --local
*** LOCAL GEMS ***
minitest (1.6.0)
rake (0.8.7)
rdoc (2.5.8)
Install RubyGems (http://rubygems.org/pages/download)
C:\>gem update --system
Updating RubyGems
Nothing to update
C:\>gem install rubygems-update
Successfully installed rubygems-update-1.3.7
1 gem installed
Installing ri documentation for rubygems-update-1.3.7...
Installing RDoc documentation for rubygems-update-1.3.7...
C:\>gem list --local
*** LOCAL GEMS ***
minitest (1.6.0)
rake (0.8.7)
rdoc (2.5.8)
rubygems-update (1.3.7)
Next install rails.
C:\>gem install rails
Successfully installed activesupport-3.0.0
Successfully installed builder-2.1.2
Successfully installed i18n-0.4.1
Successfully installed activemodel-3.0.0
Successfully installed rack-1.2.1
Successfully installed rack-test-0.5.4
Successfully installed rack-mount-0.6.13
Successfully installed tzinfo-0.3.23
Successfully installed abstract-1.0.0
Successfully installed erubis-2.6.6
Successfully installed actionpack-3.0.0
Successfully installed arel-1.0.1
Successfully installed activerecord-3.0.0
Successfully installed activeresource-3.0.0
Successfully installed mime-types-1.16
Successfully installed polyglot-0.3.1
Successfully installed treetop-1.4.8
Successfully installed mail-2.2.5
Successfully installed actionmailer-3.0.0
Successfully installed thor-0.14.0
Successfully installed railties-3.0.0
Successfully installed bundler-1.0.0
Successfully installed rails-3.0.0
23 gems installed
Installing ri documentation for activesupport-3.0.0...
Installing ri documentation for builder-2.1.2...
Installing ri documentation for i18n-0.4.1...
Installing ri documentation for activemodel-3.0.0...
Installing ri documentation for rack-1.2.1...
Installing ri documentation for rack-test-0.5.4...
Installing ri documentation for rack-mount-0.6.13...
Installing ri documentation for tzinfo-0.3.23...
Installing ri documentation for abstract-1.0.0...
Installing ri documentation for erubis-2.6.6...
Installing ri documentation for actionpack-3.0.0...
Installing ri documentation for arel-1.0.1...
Installing ri documentation for activerecord-3.0.0...
Installing ri documentation for activeresource-3.0.0...
Installing ri documentation for mime-types-1.16...
Installing ri documentation for polyglot-0.3.1...
Installing ri documentation for treetop-1.4.8...
Installing ri documentation for mail-2.2.5...
Installing ri documentation for actionmailer-3.0.0...
Installing ri documentation for thor-0.14.0...
Installing ri documentation for railties-3.0.0...
Installing ri documentation for bundler-1.0.0...
Installing ri documentation for rails-3.0.0...
Installing RDoc documentation for activesupport-3.0.0...
Installing RDoc documentation for builder-2.1.2...
Installing RDoc documentation for i18n-0.4.1...
Installing RDoc documentation for activemodel-3.0.0...
Installing RDoc documentation for rack-1.2.1...
Installing RDoc documentation for rack-test-0.5.4...
Installing RDoc documentation for rack-mount-0.6.13...
Installing RDoc documentation for tzinfo-0.3.23...
Installing RDoc documentation for abstract-1.0.0...
Installing RDoc documentation for erubis-2.6.6...
Installing RDoc documentation for actionpack-3.0.0...
Installing RDoc documentation for arel-1.0.1...
Installing RDoc documentation for activerecord-3.0.0...
Installing RDoc documentation for activeresource-3.0.0...
Installing RDoc documentation for mime-types-1.16...
Installing RDoc documentation for polyglot-0.3.1...
Installing RDoc documentation for treetop-1.4.8...
Installing RDoc documentation for mail-2.2.5...
Installing RDoc documentation for actionmailer-3.0.0...
Installing RDoc documentation for thor-0.14.0...
Installing RDoc documentation for railties-3.0.0...
Installing RDoc documentation for bundler-1.0.0...
Installing RDoc documentation for rails-3.0.0...
Let's see what's installed.
C:\>gem list --local
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
erubis (2.6.6)
i18n (0.4.1)
mail (2.2.5)
mime-types (1.16)
minitest (1.6.0)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rdoc (2.5.8)
rubygems-update (1.3.7)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)
Let's create a new app to see if it works.
C:\>rails new testapp
create
create README
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/controllers/application_controller.rb
create app/helpers/application_helper.rb
create app/views/layouts/application.html.erb
create app/mailers
create app/models
create config
create config/routes.rb
create config/application.rb
create config/environment.rb
create config/environments
create config/environments/development.rb
create config/environments/production.rb
create config/environments/test.rb
create config/initializers
create config/initializers/backtrace_silencers.rb
create config/initializers/inflections.rb
create config/initializers/mime_types.rb
create config/initializers/secret_token.rb
create config/initializers/session_store.rb
create config/locales
create config/locales/en.yml
create config/boot.rb
create config/database.yml
create db
create db/seeds.rb
create doc
create doc/README_FOR_APP
create lib
create lib/tasks
create lib/tasks/.gitkeep
create log
create log/server.log
create log/production.log
create log/development.log
create log/test.log
create public
create public/404.html
create public/422.html
create public/500.html
create public/favicon.ico
create public/index.html
create public/robots.txt
create public/images
create public/images/rails.png
create public/stylesheets
create public/stylesheets/.gitkeep
create public/javascripts
create public/javascripts/application.js
create public/javascripts/controls.js
create public/javascripts/dragdrop.js
create public/javascripts/effects.js
create public/javascripts/prototype.js
create public/javascripts/rails.js
create script
create script/rails
create test
create test/performance/browsing_test.rb
create test/test_helper.rb
create test/fixtures
create test/functional
create test/integration
create test/unit
create tmp
create tmp/sessions
create tmp/sockets
create tmp/cache
create tmp/pids
create vendor/plugins
create vendor/plugins/.gitkeep
Smashing! Let's change directories and start the server.
C:\>cd testapp
C:\testapp>rails s
Could not find gem 'sqlite3-ruby (>= 0, runtime)' in any of the gem sources.
Try running `bundle install`.
Forgot to run the bundler.
C:\testapp>bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.0)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.0)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.4)
Using tzinfo (0.3.23)
Using actionpack (3.0.0)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.5)
Using actionmailer (3.0.0)
Using arel (1.0.1)
Using activerecord (3.0.0)
Using activeresource (3.0.0)
Using bundler (1.0.0)
Using thor (0.14.0)
Using railties (3.0.0)
Using rails (3.0.0)
Installing sqlite3-ruby (1.3.1)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Notice bundler installed sqlite3-ruby(1.3.1).
Let's look at the gems again.
C:\testapp>gem list --local
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (3.0.0)
activemodel (3.0.0)
activerecord (3.0.0)
activeresource (3.0.0)
activesupport (3.0.0)
arel (1.0.1)
builder (2.1.2)
bundler (1.0.0)
erubis (2.6.6)
i18n (0.4.1)
mail (2.2.5)
mime-types (1.16)
minitest (1.6.0)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.4)
rails (3.0.0)
railties (3.0.0)
rake (0.8.7)
rdoc (2.5.8)
rubygems-update (1.3.7)
sqlite3-ruby (1.3.1 x86-mingw32)
thor (0.14.0)
treetop (1.4.8)
tzinfo (0.3.23)
let's start the server!
If you get and error message about the SQLIte3 gem, here's how I solved it.
C:\testapp>rails s
=> Booting WEBrick
=> Rails 3.0.0 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2010-09-01 09:26:43] INFO WEBrick 1.3.1
[2010-09-01 09:26:43] INFO ruby 1.9.2 (2010-08-18) [i386-mingw32]
[2010-09-01 09:26:43] INFO WEBrick::HTTPServer#start: pid=4044 port=3000
Now go to http://127.0.0.1:3000/
What are we running?
Have fun.
Next we'll get it to hook up to MySQL
Monday, June 14, 2010
Create A Rails 3 beta With Authlogic, Declarative Authorization a
Create A Rails 3 beta With Authlogic, Declarative Authorization and Cucumber
Let's get going.
bootstrap your Rails app, for rspec:
run
C:\web\auth_with_roles>rake db:migrate
C:\web\auth_with_roles> rails g authlogic:session user_session
fix up the sign up form /app/views/users/_form.html.erb
fix the user index fix /app/views/users/index.html.erb
modify the user model /app/model/user.rb
we'll need to modify the cucumber test /features/manage_users.feature
run
Now modify the user's index spec /spec/views/users/index.html.erb_spec.rb
All tests are passing, although they are not complete.
Let's get the User model working /spec/models/user_spec.rb
Now create the Roles scaffold
create the join table
C:\web\auth_with_roles> rails g model assignment user_id:integer role_id:integer
C:\web\auth_with_roles> rake db:migrate
update the models to
in /app/models/role.rb
in /app/models/user.rb
run some tests
run
We need to add vilidation to the Role model /app/models/role.rb
run
Passed.
run
We need to add vilidation to the Role model /app/models/role.rb
run
We need to lock down the roles controller to admin only
In the application controller /app/controllers/application_controller.rb add
In the role controller /app/controllers/roles_controller.rb add
In the user controller /app/controllers/users_controller.rb add
Well we got redirected to the home page. We'll have to log in.
in /featues/manage_roles.feature add
in /featues/step_definitions/user_steps.rb add
Let's update the users feature so we can select a role for a new users and admin can show edit or destroy. everyone can see a list of the users
run
It passes.
Remove the previous @focus from feature
run
we need to modify the index view /app/views/users/index.html.erb
We will need to fix the delete user scenario. remember to move the @focus tag to it.
run
run
Let's updae the index page /app/views/users/index.html.erb
run
Let's test all the cucumber tests
Cheers,
Source code on git hub.