Skip to main content

Posts

Showing posts with the label new

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...