Skip to main content

Posts

Showing posts with the label naming conventions

Modifying Migrations

As I continue my study of RubyOnRails using Build Your Own Ruby On Rails Web Applications by Patrick Lenz, I'm including expansions on certain topics that piqued my interest. First, here are a few useful links if you're reading the book too. book web site book errata ruby on rails docs I learned a little bit more about how rake handles automatic migrations today. I suspected that like it's similarly named counterpart rake might determine which migrations to apply based on the last change date of the migration file. I was wrong. I had created a new migration to add a column to one of my models. I ran rake and everything went without a hitch. Then, about two minutes later, I realized that I still needed to add one more column to that particular model. I didn't want to create another migration file for the second new column. "No problem," I reasoned. "I'll just add a new column to my latest migration file." I did this, ran rake, and not...

The Default Debacle

As I continue my study of RubyOnRails using Build Your Own Ruby On Rails Web Applications by Patrick Lenz, I'm including expansions on certain topics that piqued my interest. First, here are a few useful links if you're reading the book too. book web site book errata ruby on rails docs Today I diverged from the examples in the book again and encountered an issue with the word 'default'. It turns out that default is a SQL keyword depending on the context of the expression it is used in. I wanted to store a default value for a record in a table. This is illustrated in the table below: user default actual tom sleep sleep bob awake sleep susy awake awake The table tracks the 'default' or usual state of each user and their current 'actual' state. This seemed simple enough. The add_column call in my migration file had no problem with the column name 'default'. However, when I tried to add items to the table, the column name 'default' ca...

The 'new' Method of ActiveRecord Further Explained

As I continue my study of RubyOnRails using Build Your Own Ruby On Rails Web Applications , I'm including expansions on certain topics that piqued my interest. First, here are a few useful links if you're reading the book too. bookweb site book errata ruby on rails docs As I continued my study of RubyOnRails, I noticed that the new method was being called with a params hash on page 157. The params hash picks up the user data on the example submission form. The hash is passed to the 'new' method and a new object is magically created with its fields automatically assigned the values that the user submitted on the web form. Previously in the book, I had seen 'new' called with no arguments, but I hadn't seen this hash argument version of the method. A little research into the Rails Framework documentation for 'new' shed some light on the situation. It turns out that 'new' can be called in four different ways. The first way is the no argu...

Experiences Using "Build Your Own Ruby On Rails Web Applications"

This is the first of a series of tech posts on this blog. I'm studying RubyOnRails, (RoR), using an excellent book: Build Your Own Ruby On Rails Web Applications . The book is easy to understand and flows well in a narrative fashion with plenty of humor thrown in. As I build my real-world application I'll post notes of interest here. These posts are intended for RubyOnRails beginners or others reading the book. Model class to database table naming: I understood from the book that a model class like 'Story' would be translated into a table name in a migration file of 'story'. What I was not aware of was that a name like 'MyBigStory' will be translated into a table name of 'my_big_story'. rake and rolling back database migrations: First, this feature of RoR is incredible! Essentially it's revision control for database schemas! With a minimum of work, the developer can maintain a framework that allows her to easily move back and forth b...