Cookin' with Ruby on Rails - May
Pages: 1, 2, 3, 4, 5, 6
Migrate back to the most current version: Version 3.

Figure 33.
(Click to enlarge.)
And our schema is reconstructed.

Figure 34.
(Click to enlarge.)
As is our database.

Figure 35.
(Click to enlarge.)
Paul: OK. So the first thought I'm getting is that, with migrations, I can pretty easily put my database under version control. So if I've got a customer-reported bug to fix and the database schema has changed since the release they're using, I can migrate my development and test systems' databases back to the version that matches the software they're running. And if there are intervening releases, I can step through the whole list doing exactly the same thing. So basically, I can check out my database right along with my code base. I have to admit, that is pretty cool.
So what do we have to do now? I mean, we've got some garbage in our migrations now. We have no idea whether or not Boss is going to want to add any information about contributors. Can we get rid of those migration files?
CB: We can, but we need to do it carefully. Rails won't like it if we get things out of synch. The easiest way to get everything back to where we started is to use Rails to migrate us back to our baseline,

Figure 36.
(Click to enlarge.)
check our schema to make sure it's what we expect,

Figure 37.
(Click to enlarge.)
check our database to make sure it's what we expect,

Figure 38.
(Click to enlarge.)
then go to the migration directory,

Figure 39.
and get rid of the garbage.

Figure 40.
Now our migrations will start again with the current version being our baseline.

Figure 41.
(Click to enlarge.)
All cleaned up and ready to move forward.
Paul: Wow. That's pretty impressive stuff! I'll have to play around with it some more. Right now, though, I've got to take off. Thanks for sharing the pie and for taking me through migrations. If we can, I'd like to pick up next time we get together with the unit tests. I'll definitely feel better when I know those are in place.
And so Paul takes off and CB goes back to his 9-5 drudgery, daydreaming just a little about what the future might hold. Could it really happen? Could this actually turn into a chance to do some serious coding in Ruby on Rails? Have some fun and get paid too? Well now, there's something I'd like a lot! Even better if it comes with free pizza! ;-)
Click to continue your adventure as CB and Paul add Unit tests to their Cookbook app.
Bill Walton is a software development/project management consultant/contractor.
Return to Ruby.
Showing messages 1 through 17 of 17.
-
great work
2008-01-16 06:34:40 lrt [View]
great work on this tutorial. please keep it up. i would like to see CB eventually work on more complicated apps, maybe incorporating Ajax and Flex/Flash for RIAs.
-
One more time:Thanks!
2007-12-20 10:37:06 pakosis [View]
Thanks for taking your time for writing this great article..
On the other hand.. Do you (guys) know any other tutorial/article involving a larger project (maybe with ajax, sesions, advance validation..)
Thank you!
Pakosis
-
Thank you all
2007-09-13 20:45:57 Staramor [View]
I've been a Affordable housing revovator, Commercial Real estate broker, day trader(er well not sure there was really an edge there but i tried), vacation home manager and a few other dabbles.
I prodded around with web sites a few years ago but couldn't really get past glorified cut and paste collage work with html or use of off the shelf php blog programs. But I have ideas! delusions of glory for new interactive web aps and sites! Trying to tinker with blog programs to turn them into other things led me to brick walls of despair. A combination of drowiness and terror overwhelmed me reading my expensive Php Mysql texts.
Recently i've stumbled on Ruby and Ajax...these are fun things! Ruby especially seems to be able to be a glue i can tinkerwith and build stuff incrementally. I've read your articles and was able to load the instant rails stuff and follow along. I think i can learn this and actualy work with this rails system. To grow an application, not conceive of it in whole and build it up with 70,000 interelaced toothpicks.
I'll echo the comments that your approach here is fresh and inspiring (i like the assides, diaglogue etc.. it works for me to have a context struture with bigger principals attached.
I've done the thing twice with re-reading a Ruby text in between. I didnt have a lot of context so even ideas of Arrays, functions, Classes, Databases were foregn words for me... but i am understanding more each time. I also am such a non linear thinker that when faced with a concept that i dont understand and dont have a context to understand i'll bang my head against it trying to comprhend an interim step anyway. Your project drags me forward within a defined concept to let plant some seeds yet let me make headway.
I also thank the people who take the time to post comments on glitches in an instruction. I was stuck until I read the comments above and who knows how much "suffering" i may have gone through if people hadn't taken the time to post.
This whole utopian idea of open source is really amazing.. and its telling that it allowed the growth of a application/system like rails that will allow things to organically grow and be improved upon.
I didnt even know that it was hard to turn on or off a column in a database but that wouldnt be for me at all! Well this whole adventure might still be a bit much for me but it beats watching tv in the evenings. Thanks for the great efforts writer and whole sharing computing community...
-
Migration Error on Linux
2007-07-10 11:41:25 waylonflinn [View]
Howdy,
I finished the article series ending at:
http://www.onlamp.com/pub/a/onlamp/2007/01/05/revisiting-ruby-on-rails-revisited-2.html?page=4
and followed the link over here. Everything seemed to go fine until I got to page 4 and the db:migrate command which runs AddContributorName (file shown here: http://www.oreillynet.com/ruby/2007/05/17/graphics/figure018_large.gif). It gave me the following error:
"You have a nil object when you didn't expect it!"
After a comparison with http://www.oreillynet.com/ruby/2007/05/17/graphics/figure019_large.gif I changed "string" to :string and got the following error:
"Mysql:Error: Table 'rollingrails_development.Recipes' doesn't exist:[...]"
I then changed 'Recipes' to 'recipes' in the add_column function. This produced the results expected.
Thanks for the excellent series,
Waylon -
Migration Error on Linux
2007-07-11 06:36:36 Bill Walton | [View]
Hi Waylon,
Sorry you had a problem, but thanks much for making the time to let me know. If you get a chance, it would be great to know what Linux distro, version of Rails, etc. you're using. I'd like to investigate / understand this better. I'm working in Windows and I'm guessing there must be some difference between it and your Linux distro that's causing this. Maybe there's a way to avoid it. Sometime in the next few weeks I'm going to go back and redo the images to make them small enough that they don't require the "click to enlarge" button and, at the same time, I'll have an opportunity to make some minor changes.
Thanks again.
Bill -
Migration Error on Linux
2007-07-29 03:00:52 Geldart [View]
Bill:
Exactly the same problem here (Ubuntu 7.04, Ruby 1.8.5, Rails 1.2.1). Fix needed seems to be two things:
- "recipes" not "Recipes"
- :string no "string"
i.e.:
class AddContributorName < ActiveRecord::Migration
def self.up
add_column("recipes", "contributor_name", :string, :default => "Unknown")
end
def self.down
remove_column("recipes", "contributor_name")
end
end
-
Migration Error on Linux
2007-07-22 10:23:19 DaveMatuszek [View]
I had the same problem using InstantRails 1.7 with
Ruby 1.8.6 and Rails 1.2.3. Capitalization of "Recipes" doesn't seem to be important, but "string" must be :string.
The error (evaluating nil.[]) occurs in
.../schema_statements.rb:272:in 'type_to_sql'
the line reads:
limit ||= native[:limit]
I also found
native = native_database_types[type]
and
def native_database_types
{}
end
and no additions to this hash. My Ruby isn't yet
good enough to figure out why this can ever work....
-
Migration Error
2007-08-14 11:25:56 ezosoro [View]
It took looking at the screen shot of the command prompt window before I got this to work correctly, as it shows something totally different then the screen shot of the "002_add_contributor_name" file.
If you use this for the "add_column" line it should work correctly...
add_column("Recipes", "contributor_name", :string, {:default => "Unknown"})
It was missing the brackets around the default value and string needs a colon and no quotations afterwards. Hope it helps everyone out ;).
-
WOW now I get it..
2007-05-24 11:06:31 randyh [View]
Thanks for the article. I'm like CB. Now I get "it"
-
WOW now I get it..
2007-05-24 11:23:04 Bill Walton | [View]
Hi Randy,
Thanks for making the time to let me know. That's really encouraging feedback!
Best regards,
Bill
-
re: code examples
2007-05-23 09:07:15 jon_austin [View]
... or simply resize all the images with a batch converter so we don't have to click on every one... -
re: code examples
2007-05-24 06:43:33 Bill Walton | [View]
Hi Jon,
I didn't realize the images would be resized for publication, requiring the 'click to enlarge'. I'll definitely incorporate your feedback into the next article re: how I handle this. Thanks much for making the time to let me know about its affect on the article's usability. I appreciate it very much.
Best regards,
Bill
-
Great Article
2007-05-21 20:22:22 asommer [View]
I really like the style of this article. The whole dialog between people is a nice way to teach the concepts.
At least for me.
Looking forward to the unit test article.
Thanks -
Great Article
2007-05-24 06:50:56 Bill Walton | [View]
Hi,
I'm glad you like the approach. And very glad to hear you're looking forward to the next one. Thanks much for making the time to let me know.
Best regards,
Bill
-
code examples
2007-05-17 12:20:27 perrin [View]
Please don't put the code examples in screen shots. They screw up printing for the article. -
code examples
2007-05-24 06:48:57 Bill Walton | [View]
Hi Perrin,
When you say 'screw up printing' do you mean that you're printing without the images and so can't see code that's only shown in the images? Or, as Jon's note suggests, that when you print the article the code shown in the images isn't readable because the images have been resized? Any info on how readers are actually using the articles is extremely helpful. Thanks for making the time to let me know. I appreciate it very much.
Best regards,
Bill -
code examples
2007-06-13 00:32:05 xeal [View]
"the code shown in the images isn't readable because the images have been resized"
That's it! Can you please update this article so your readers can actually use the for-print version? It's unusable as it is now.









