Fun stuff - Oscar Picks !!
My friend David did a fun thing, Oscar Picks!
You can even get a widget and display on your blog:
Here are my picks:
My friend David did a fun thing, Oscar Picks!
You can even get a widget and display on your blog:
Here are my picks:
I know that mentioning Rails and PHP in the same sentence is taboo and can incite many flame wars. But hear me out — Some say one of the “downfalls” of PHP is that its so easy to write applications and just about anybody can write a PHP if they put their mind to it and learn the syntax. As a result, PHP Applications have a long history of badly written, insecure code and has really been shunned by many advanced developers (aside from many poorly named methods, I think PHP is alright!).
In recent months I’ve been recruiting for a Rails Developer at my company, in Chicago. I did a phone interview and the guy couldn’t name me any rails sites he reads, or name the 7 rest actions, or even tell me what version(s) he uses. Now, I’m not claiming to be an expert, but I would think that even an average Rails developer would know that.
I’ve also seen code where the developer doesn’t quite get MVC. You don’t need to be validating values in your controller and adding error messages to @model.errors.add for example. You don’t need to be setting up display labels in your model. You don’t need to be counting things in a helper method. I was thinking, why is it so hard? Is it because in mostlanguages we have had free reign to interpret MVC however we pleased? I know I spent many years in PHP trying to develop a DAO. I made an object that returned a row of data, with methods to access the fields. But what about a collection? what is that? I experimented with an array of objects but I felt that was too wasteful. Iexperimented with a DaoSet that was made to hold a collection — complete with iterators! I even struggled with MVC and knowing what went where…when I saw Rails it was like someone who met their true love — this is it!
After experiencing Rails, I realized hey I can do some of this in PHP! I wrote a simple MVC framework in PHP. I called it StupidlyEasyMVC Framework. I was able to use it at work (at the time, I was still at a PHP job. Some say I talk about that time in my life as if it were a prison sentence haha). SO I was able to apply things I learned from Rails, into an existing structure at work. Just like the guy from CDBaby — I couldn’t drop my existing PHP site and just start converting to Rails, but by starting to gradually switch from what I had to an MVC structure, it made my code cleaner and easier to work with.
So as I look for advanced rails developers, I find they are far and few between. Either they are hotshot consultants or working on their own startup. What makes a rails programmer “get it” and really work with the framework instead of against it - still trying to write as they always have?
Here are some things you can do if you feel you are still writing PHP or .NET code in rails..
Get a project. You can read and dabble all you want, but if you don’t have a project, you won’t be forced to learn. Along with that, you need a timeline to force you to keep at it!
Watch all the Peepcodes! especially the REST and rspec episodes. I’ve search hard and long enough for answers, to find comprehensive training in ONE spot, in such an easy to learn format is awesome. I constantly talk about peepcode and I won’t work with anyone who hasn’t watch them.
Peepcode Code Review - their first book, full of helpful hints and gotchas that will really help you move beyond a beginning developer
Ruby Inside Blog - www.rubyinside.com
Jay Fields - http://blog.jayfields.com/
Obie Fernandez - obiefernandez.com
Books:
Agile Web Development with Rails - If you are doing Rails and don’t have this book, get it! It is the bible of rails! I don’t care if you have the first edition already, this will save you time!
The Ruby Way by Hal Fulton - because if you don’t know ruby, you will never be a good rails developer.
The Rails Way by Obie Fernandez - its good because I tech edited it before publication! It is a comprehensive instructional and reference book — all in one. I cannot wait to get my hands on a paper copy of this to keep at home and one for work. (just got one this week…I’m ecstatic)
Well this has been mostly a rant but hopefully a help resource to move into more advanced development of rails. If you have other insights into this problem or suggestions for how to improve, please leave a comment!
I finally made it to a ruby related conference! I almost went to the past two rails confs but something always came up (like — new jobs!). Looking forward to meeting lots of people..
So far the session on Advanced Class Design is awesome… more updates to come
Its been a while since my last post! Been so busy working on ruby, at work, at home and play. Some of the interesting things I’ve been doing recently:
Conductors - I’ve been fascinated by the Presenter Design Pattern posted by Jay Fields and more here and read up everything I could, still it wasn’t quite what I wanted. Then I found the blog entry by New Bamboo Conductors and Presenters. Basically a conductor goes between model and controller whereas a presenter goes between a view and model. A conductor is what I’ve been wanting — a way to group to associated models such as customer and an order and work with it as one. I can call save on it,I can pass it to a form builder (which is sort of present-y but I don’t care) Anyways, I am working on a blog post about it.
Exporting data to fixtures - for one project, I wanted to extract a subset of data to fixtures so I can load into a staging site for testing. Say I wanted to take the most recent 100 orders, which also grabs the associated record from customers, addresses, invoices, customer categories and products table. With the help of one of the recipes in the Rails Recipes (Pragmatic Programmers) I was able to write a rake task to export the data. The example exported all data from every table except schema_info. I rewrote it with explicitly naming the tables and the queries needed. I’ll write up something on this too, including how I got around my yaml array being TOO large(I think thats the prob anyways) to import! doh!
Admin interface - I used the restful_authentication plugin. That’s great for a sign up and login page but I also wanted a way to administer users. I debated on whether to make an controllers/admin/users_controller and banish anyone trying to access that controller and not an admin … or, I can add the CRUD methods to the controllers/users_controller and check for admin at the start of the CRUD actions that only admin can use. I turned to the wisdom of the DevChix mailing list (sorry boys) and got some good ideas from the Chix. I need to write this up as well!
Facebook App - Not Rails, but could be. I was recently contacted by someone to make a facebook app. I’ve never made one, so that night I set out with PHP to write a little app. Within a few hours, I had a simple app. I let the company know that I figured out how to do it, and what was the next steps in getting the contract? *poof* they never emailed me back. I think they figured — well if SHE can do it two hours, we can probably figure it out ourselves! haha… but it was fun anyways.
Rspec and Mocks - It took me awhile to get the hang of mocks… but determined I figured it out. Nice.
Right now I am just using the mocks in rspec, but want to look at other mocking frameworks to see what the difference is.
Autotest and snarl/growl - I now use autotest all the time on all my projects. I saw on PeepCode that Geoffery used growl to make a small window pop up on his mac with the status of the last run test. I showed my husband and said SEE? I need a mac. I thought there must be a windoze thing that does the same thing, I searched and found this post on SourceCraft Blog where the author talks about setting up autotest with Snarl (for windoze). I tried my darnest to get it to work on windoze and popup a snarl message (like you cool mac kids with your growl notifications) .. and there’s a bug somewhere because it says every time 100% tests pass..and I know I’m not that good. Haven’t worked on it in awhile though, so I should try again I guess (or get a mac, which I am trying to do!)
rcov - one project I was working on went pretty fast (one danger of doing Rails for people that are used to “other” languages) and I was accused of not making quality code! so I installed rcov and showed them my 100% test coverage. I know rcov doesn’t tell you how “good” your code is, but it does tell you its well tested. How about them apples? ok, I’m a smartass sometimes.
The Rails Way - I was one of the technical reviewers for “The Rails Way” written by Obie Fernandez. It was a fascinating read and I learned a ton. I can’t wait for the paper book to be printed, due out in October (The site says November, so maybe I am mistaken on October). If you do Rails — get the book! I’ll post a more detailed review when the book is out.
PeepCode.com - I’ve been an avid PeepCode.com fan from the first screencast I purchased — about REST. I watched the episodes on TDD and the two about RSpec. This was very helpful. See, one problem I find with learning rails stuff is that there are all sorts of blogs on something, and sure by picking up pieces here and there you COULD probably get the learning you would gain from PeepCode.. but with PeepCode, its all in one spot and you can SEE it works, which is key for me. There is alot to be said for “seeing” something work to solidify the process in your mind — but everyone learns different so that probably doesn’t work for everyone.
Watching the rails commits - Ok so maybe I need a life. I’ve been watching the rails commits every day and seeing what changed. Alot of clean up going on it looks like. One of these days (soon I hope), I’ll test some of the patches or try to fix a bug.
Lots of stuff going on and I’m having fun.
Book Site | Sample Chapter: The Theme System | Table of Contents
Many of you are aware of my current total infatuation with Ruby, and that I’ve
used PHP for about 6 years and at one point decided I hated PHP…until, I
needed it for a quick one-off page and then realized that PHP had its place.
Then again, I was totally frustrated with Ruby when making my moms bakery site and then turned to Drupal and Gallery (another fine PHP project), which saved my bacon and I got a website and photo gallery up in a weekend. So, PHP and I have had our moments but I’m not abandoning it!
Drupal powers some big sites, its not just for joe smoe’s blog. This is an interesting page about Is Drupal Right For You? and if you are wondering if its something that would even work for you.
I was excited to get my hands on a review copy of Pro Drupal Development. Its no
secret that coders hate documentation and Drupal has one of the most complete
online documentation I’ve seen for an Open Source project, but its almost too
hard to find what you need amongst so much. The Pro Drupal Book is a godsend for
the drupal programmer, new and experienced alike. I wish it was written a year
ago!
The book starts off with a quick overview of how Drupal is structured and
defines terms such as hooks, node and blocks in just 10 pages. Chapter 2 is a A
step-by-step tutorial with making a module. That is a great idea to start off
quickly writing code. It get the reader involved and hands on. I really tire of
books that have to start off with the history of the internet, html and how
things have evolved. Get to the code dangit!! Kudos to the Authors for that!
Chapter 3 gets into module specific settings, like how to get your module to
show up on the admin page and storing user settings that your module needs.
After you’ve had some experience with the code then the book goes into details
on the specific parts of Drupal:
Drupal is a pretty amazing framework, when I read the code I say “why didn’t I think of that?” … the module and hook system is genius.
Then some more general topics:
One of the chapters I skipped ahead to read was The Form API. In my years of PHP
I’ve often tried to come up with a framework for doing forms and I wanted to see
how they did it. This chapter follows a tutorial style as well. The Form API
allows you to define fields, their label, their value, description. Some
frameworks take the template approach, where you hammer out your HTML. Some are
more configuration based like Drupal making a multi-dim array with keys and
values. I can see advantages to both. There is a hook function for validation
which allows you to write your validation checks.
PHP gets a bad wrap for security, partly because its pretty easy to learn
PHP and newbies don’t always realize what they are doing. There is a
chapter devoted to security and includes even some things I didn’t know about –
encoding mail headers. The Form API is very secure, one thing it does is
check values that come from dropdowns were actually in the options and it wasn’t
something that the hacker made up.
Developer Best Practices are great for the new developer, it talks about using
cvs, tags, branches. It talks about how to create and apply patches (hint - you
can contribute back to drupal). That is awesome. Alot of open source projects
are like “HELP us, submit patches!” and the new user is left with uhhhhhh..how?
Caching is another interesting chapter. You will learn how caching works
and how Drupal Core uses it. There is a Cache API that has methods for module
creators to make their modules faster.
JQuery … I am not sure if I like it or not, but its part of Drupal 5! I
skipped ahead to this chapter to see what its all about. There is a javascript
hook built into Drupal making it easy to add, thats pretty cool.
One thing I found lacking in the book is anything about Testing. There are few
pages on debugging and some modules to help with testing, but I would like to
see more. At least some talk about selenium, which is great for a site made with
any framework/cms.
Over all, Thanks APress for another great book!
I did PHP for 6 years.... sometimes its hard not to do PHP in ruby...
Today i was testing a url to see if it contains a certain string:
and remember to do:
Another thing I was working on was I had to do a multiple if statement
I will simplify it for this example:
In PHP I might have actually made the values into an array, and then did in_array ... but in reading the code, you see below, if in the valid values, print something. I don't want to see array!
This is more elegant:
This seems to only work for values you'd do == on, not ===
See... programming in ruby just makes me grin
When I posted at the Rails-Forum, I also emailed the internal DevChix list (sorry boys!) because I was totally at wits end about this problem. (got no response from Rails-Forum BTW) and at least I got some ideas...
Jen-Mei said to try this:
That worked as expected!! So that was not the problem...
Sandi M. had this idea:
By this point, we had taken the conversation to instant messenger..
Hmm... so I saw it trying to work... I got an error saying argument error with expecting 4 params and only getting 2! Jen-Mei had me do a grep to see if type_to_sql is defined anywhere -- and AH HA.. there was a plugin -- mysql_bigint that was installed, and it had redefined the method and that was the culprit. This was a codebase that I inherited so I didn't even know what that plugin was used for or anything.
Here was the code in mysql-bigint plugin
Did a bit of research and found I had an old version installed:
http://www.northpub.com/articles/2006/10/29/new-version-of-mysql_bigint-rails-plugin
Quote from the site: "I received some feedback that edge Rails broke some things in the mysql_bigint plugin . I've checked in a new version that works correctly with edge rails. Thanks to Jamie Orchard-Hayes for a patch that fixed a few of these issues!"
So, I see there's a fix for it... but upon further investigation, the plugin is not use in the application at all! So I removed it for now.
Things I learned:
First the cool thing... and I think I have a good reason for this... I have a model that is not tied to any particular table, but is a summary table for about 8 tables. Rather than cluttering up my controller with a bunch of stuff, I am putting into a model (keeping REST in mind). I could have put it in the lib dir as a module.. but.. I thought i'd try it in the models dir, so i don't have to require it etc. And later I realized I need a bunch of fixtures for it, so I think its pretty handy as a model. Of course, I took out the base class of active record
app/model/summary.rb
I might want to get the count of jobs for ALL time or a data range, so if there are dates set, it uses those. In addition to jobs, I need to do some 'not so easy" counting of other date and so i started changing my test fixtures to something like this:
test/fixtures/summary_report/jobs.yaml
I have a bunch of other tests and I found one of them was not quite right, and my additional fixtures for the summary report messed it up. So I made a directory in test/fixtures/summary_report and then loaded the fixed in my summary test as such:
test/unit/summary_test.rb
So I put fixtures for a particular set of tests in a directory in fixture. Is there a better way to do this?
I put it in a post I made on ruby-forum.com but here it is again:
Basically, when I try to use a rails version higher tha 1.1.6 in my vendor/rails directory my migrations don't have "varchar" they have "string" !! WTF! ... I even tried sqlite and same thing.
I've searched all over the web and mailing lists and can't find any info
on this problem.
I have a site built with Rails 1.1.6 I ran
rake rails:freeze:edge TAG=rel_1-2-3
I ran db:migrate (on a fresh database)
rake db:migrate VERSION=1 --trace
(in /home/nola/projects/tardis/website/trunk)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== AddContact: migrating
======================================================
-- create_table(:contacts)
rake aborted!
Mysql::Error: You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'string DEFAULT NULL, `city` string DEFAULT NULL)
ENGINE=InnoDB' at line 1: CREATE TABLE contacts (`id` int(11) DEFAULT
NULL auto_increment PRIMARY KEY DEFAULT NULL, `name` string DEFAULT
NULL, `city` string DEFAULT NULL) ENGINE=InnoDB
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:128:in
`log'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:243:in
`execute'
/home/nola/projects/tardis/website/trunk/config/../vendor/plugins/mysql_bigint/lib/mysql_bigint.rb:32:in
`create_table'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/connection_adapters/mysql_adapter.rb:353:in
`create_table'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:275:in
`method_missing'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:259:in
`say_with_time'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:259:in
`say_with_time'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:273:in
`method_missing'
./db/migrate//001_add_contact.rb:3:in `real_up'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:212:in
`migrate'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:212:in
`migrate'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:335:in
`migrate'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:330:in
`migrate'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:297:in
`up'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/activerecord/lib/active_record/migration.rb:288:in
`migrate'
/home/nola/projects/tardis/website/trunk/config/../vendor/rails/railties/lib/tasks/databases.rake:4
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:392:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:362:in `invoke'
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:355:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1739:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake- 0.7.3/lib/rake.rb:1739:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1733:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake- 0.7.3/lib/rake.rb:1711:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1761:in
`standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.7.3/lib/rake.rb:1708:in `run'
/usr/lib/ruby/gems/1.8/gems/rake- 0.7.3/bin/rake:7
/usr/bin/rake:1
----------------------------
SO Basically, its trying to put in a sql create statement like this:
CREATE TABLE contacts (
`id` int(11) DEFAULT NULL auto_increment PRIMARY KEY DEFAULT NULL,
`name` string DEFAULT NULL,
`city` string DEFAULT NULL
) ENGINE=InnoDB
string? when it should put in VARCHAR(255) .. weird huh?
Here's the migration:
class AddContact < ActiveRecord::Migration
def self.up
create_table :contacts do |t|
t.column :name, :string
t.column :city, :string
end
end
def self.down
drop_table :contacts
end
Any ideas? I've also tried with rel_1-2-0 too... and get the same
result. I can create a table with ints or no fields just fine. When I
remove vendor/rails then its fine.
Hey ... a friend at oscon send me this survey PerlSurvey ... if you do perl, take it and let your voice be heard!
I've been kinda on a rails spree lately, I guess I've had some free time and also redoing a rails 1.1.6 project (and was noob then and no clue of what I was doing) and updating it to use REST.
I got Geoffrey Grosenbach PeepCode's REST Tutorial, which is very awesome and well worth the 9 bucks. Its over an hour long! I also got the RJS Tutorial which is also awesome. I can't wait till payday to get the $40 pack so I can get some more! There's just something about SEEING something work that makes it stick sometimes.
Also I spent some time on Railscasts which features a ton of short demos on rails topics. Very cool. In particular i liked Testing Without Fixtures which is cool because sometimes fixtures are a PITA!
When watching one of the PeepCode screencasts I saw him using "autotest" .. a cool toy which I must have too! I searched for it and found this posting on his blog. Now I'm autotesting all the time
It basically monitors your rails site and runs the test everytime you change your code.
I've been using e-TextEditor and slowly learning the shortcuts. I love the font that was on PeepCode's screen cast and found a link on the PeepCode FAQ where I can download it. For Free! And it mentioned the name of the theme used in Textmate -- which happened to be the one I had found in e-Text-Editor and was using. No wonder I liked it! I also used this font in my Putty settings and changed the awful default colors (esp that dark blue! hard to see!). e-TextEditor is in Beta but its in great shape and i was so happy to see a "close all tabs" feature put into the latest build. I'll be ecstatic when they make a linux version.