Rails
Catch-up
Owing to the domain / DNS / hosting drama of the last few weeks, I’ve not been very motivated to post. Partly because I thought that investing any time and effort into the old site might make it harder to migrate to a new site. Further, after spending tons of time trying to get some non-responsive, irresponsible business owner to do what you contracted with them to provide, I just simply lost my zest for posting.
But, let me summarize a few things that tell where I’m at roughly.
Work Decommission and migration are the orders of the day. I’m working on an interesting project now for horizontal aggregation of tag metadata across vertical data channels.
Getting back on the Rails: Headaches around Rails 2.x
I decided to spend some of my Christmas break taking a look at Ruby on Rails again and trying to get an application together under this application stack. Since I last looked at Rails, it had crossed the 1.x to 2.x version marker and several changes manifested. For someone trying to follow the 1.x tutorials or the canonical reference book Agile Web Development With Rails, one doesn’t make very much progress before the changes with respect to scaffolding bite one. One may need a bit of a tutorial on Rails 2.x scaffolding before being “pretty close” to training documentation. An excellent tutorial for this content was found at Fairleads.
Scaffolding has changed in Rails 2.0: Has it become un-Agile?
This is the mail that I sent to Rails-list which describes my issues around the Rails scaffolding in Rails 2.0.
Hello,
I’ve read the (many) re-posts about problems around scaffolding in Rails 2.0 and have followed a number of tutorials and fully understand “how to scaffold” from a technical perspective, but I don’t understand the mindset of how to use the new scaffolding. It seems like a productivity- / agility- regress and I’m thinking I may have failed to properly grok the new setup. In the interest of full disclosure, I’m coming back to Rails after being in other toolkits for about 9 months.
Rails: Loading test data with fixtures
Rails canonical story is:
“Fixtures are used to load sample data before a unit test”. “Migrations are used to build DB tables and alter structure of contents thereof ( e.g., delete the “name” column and split the field on comma and put the resultant entries into the “firstname” column and the “lastname” column )” But what if you need to bring in some good data – not test data, but data that you want for testing and seeing how things look with a “real” data set? What then smarties?
Here was my situation: I had entered data via the scaffolded interface and the the data included many unicode characters (&258;eae, etc.
[Rails]: Is script/console not doing what you expect?
This is more of a reminder to me for when I bang my head against the wall often and hard
>>reload!
Rails and Unicode and PostGres DB (Oh My!): Understanding how UTF-8 works
Examine the Unicode standard’s code page collection for “Latin small letter a with macron”.
Nets U0100.pdf
“Latin small letter a with macron” appears on chart as 0101. This is a hexidemial number which points to U+0101 as its code point. Converting 0101 to decimal gets you 257, this is the same as the HTML entity code. Thus one can enter either ā or ā and get the right glyph [ā|ā]
Put ā character into a view via Rails that is back-ended by a PostGres database.
Using script/console, write the collection of models that contain this accented character to a YAML file.
[Rails]: Steven's Guide to: "Many to Many Associations" or "HABTM" (1/2)
The concept: “Many to Many” relationships Many things in this life have a one to one relationship: a man has a wife ( Utah excepted ), a car has an owner, a dog it’s day. Many other things in life have a one to many relationship: a policy covers many people, a manager has direct reports, etc. But some things have a many to many relationship. People have surnames (“John Smith” is a Smith and so is “Jane Smith”;conversely, among the Smith clan there might be multiple Johns, 42 Janes, and 22 Larry’s ).
It is of this many to many relationship I will write and whose code I seek to share.
[Rails] Cleaning up HABTM views (2/2)
The reality is that most people use Rails for web frameworks … the console manipulation stuff we explored in the previous post doesn’t really help us much. We need a web interface. While using the script/generate gave us some scaffolds that we can play with, it’s not really “integrated” and it doesn’t quite demonstrate the “has many”-ness.
First we’ll fire up the web server (script/server) and see what the ’new’ view looks like:
Hm, that’s certainly not giving us any place to enter some flavorful information. Let’s fix that in the view.
<p> <b>Flavors ( comma-delimited )</b><br/> <%= f.text_field :flavorstring %> </p> Try reloading the view…
Me lately...
Rails…
…Lauren
Rails…
…work
Rails…
…school next week
Rails…
…Unicode
Rails…
[Rails] Associations
Yesterday I found out I had made a major boo-boo in setting up an ActiveRecord::Association.
Imagine a “Widget” model that is composited of serveral other fields. You might think to yourself.
“An Widget has a SKU ( housed in table ‘skus’ based on model SKU ), a widget has a color, etc.”
You then might model your code such that
Widget < ActiveRecord::Base has_one :sku has_one :color end And accordingly
SKU < ActiveRecord::Base belongs_to :widget end This is wrong.
You must think in terms of the most “atomic” element. What’s the relationship of a SKU? A SKU “has one” product to which it is applicable.
PostgreSQL database automatic launch on OSX 10.6 Snow Leopard
It took a while to find this, but here’s my solution
Add this file: /Library/LaunchDaemons/org.postgres.launchd.plist
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd";> <plist version="1.0"> <dict> <!-- Following the launchd man page enumeration of keys --> <key>Label</key> <string>org.postgres.launchd</string> <key>Disabled</key> <false/> <key>UserName</key> <string>_pgsql</string> <key>GroupName</key> <string>_pgsql</string> <key>Program</key> <string>/usr/local/pgsql/bin/postmaster</string> <key>EnvironmentVariables</key> <dict> <key>PGDATA</key> <string>/usr/local/pgsql/data/</string> </dict> <key>RunAtLoad</key> <true/> </dict> </plist> You can then load it and unload it by issuing:
$ sudo launchctl load /Library/LaunchDaemons/org.postgres.launchd.plist $ sudo launchctl unload /Library/LaunchDaemons/org.postgres.launchd.plist Now get to making some great Rails stuff!
My First Week of Development at Carbon Five: By the Numbers
It may be a bit of a “no duh” observation to point out that joining a consulting firm has a very different work flow versus working in corporate. A few numbers:
Number of days when pairing occurred: 5 Number of hours spent pairing: ~37 Number of stand-ups: 5 Time spent in stand ups (week): ~ 50 minutes Brown Bag Lunch: 90 minutes Emails received within project team: 3 Emails received from client: 1 Skills Worked On: HTML5, CSS3, Rails, Backbone.JS Times astounded by my pair’s refactoring skills: 2
A Beginner Again: Rails 4.0 + Ruby 2.0 on Ubuntu VPS
I’ve been programming Rails for a while now, and with the major releases I feel like I’m back to square one. There’s new gotchas, new strangeness talking to the databse, etc. As I encounter strangeness, I’m documenting it here.
I started by installing rbenv and Ruby 2.0. I then followed this Stack Overflow post on how to install edge Rails. I really like this approach because it makes use of Git submodules.
Things after I got Edge rails installed, I then set up my Gemfile. I don’t want CoffeeScript so I handled that by commenting out its line in the Gemfile.