Dev box
I'm a 32-year-old Ruby on Rails web developer. With the help of friends and co-workers, I've been teaching myself Rails. I worked as a Rails developer for Crowd911 in Colorado. I live in Berlin.
In my developer blog I publish a stochastic array of thoughts and ideas, lessons, mistakes, questions and attempts as answers about Rails and Ruby. I am also posting Anki cards that I used to help myself study. In my view most knowledge is about practice. If you have thoughts, questions, ideas, corrections, arguments, feel free to email me at henryvw@gmail.com.

Kernels - objects that already come with methods

The Kernel Module is a „kernel“ - an object that already has methods associated with it.  In Ruby, this kernel is what enables you to have methods like puts and gets that are not attached to a particular object.  In fact, they are part of the Kernel Methods attached to the Object calledMain.

Read More

Action Pack

The Action Pack is the the View and Controller together - since they are so intimately connected.  This is what the user of the website really experiences - the view (design) and the actions (methods in the controller like ‚create‘.)  The Controller is the logical center, the hub, the NORAD, for your app and your code.  It coordinates the interactions between the user, the view, and the model.  ***Rails handles most of this interaction behind the scenes.*** (What does that mean exactly?)

Controller

  • Manages routing external requests to internal actions (I don’t really know how this is different than 
  • Manages Caching (what does this mean?  I don’t know)
  • Manages Helper modules, which extend capability of the view template without bulking up their code
  • Manages sessions, giving users the impression of ongoing interaction with our application

 

Read More

ORM - Object-Relational Mapping - and

Object-Relational Mapping is when an object oriented programming language has to be turned into a scalar language.  Scalar means that variables can only hold one type of value, as in C or SQL. For example, a MySQL table can only hold strings, integer, etc.  Whereas a Ruby object / variable can have many attributes, and does not need to be only a string object, or only an integer.  

An ORM layer maps tables to classes, rows to objects, and columns to attributes of those objects.  ActiveRecord is the ORM layer supplied with Rails.

ActiveRecord relieves us of the hassle of talking in SQL or PostGres to a database.  Instead we can just use Rails / Ruby:

order = Order.find(1)

order.pay_type = „Purchase Order“

 

order.save

Read More

How Rails reads your URL to interpret controller verbs

In Agile, the authors explain that when a user navigates to localhost:3000/say/hello, rails matches the route pattern.  It is Restful, I think.  Rails reads say as a controller and hello as one of the actions listed in the controller.

It creates a new instance of the Ruby class SayController

It creates a new object holding the current time and puts it into the instance variable @time.

It looks for a template (i.e. a view… view = template and template = view) to display the variable

Rails Parlance

In Rails one calls methods that help make the view/template easierhelpers“.

In Rails one calls methods in the Controller handling RESTful requestsactions.“

In Rails one calls RESTful POST requests „create“ actions in the controller.

 

The Controller Asks the Model for Information, for Data.  The Controller tells the Model what to do (find information (GET), add it to the shopping cart (POST).  The Model knows how to do these data requests.  

Read More

ERB versus HAML

ERB

The ERB of html.erb is a system to interpret code in an html.erb file between <%= and %> as Ruby code and executed.  In HAML all you need to trigger the computer to read a line as Ruby code is an = (equal sign)

ERB: <%= Time.now %>

HAML: = Time.now

As you can see, HAML is cleaner. 

Fun HAML Tricks

For many types of embedded Ruby code, the = sign replaces the ERB <% = %>.  This apparently is if the code is intended for display.  E.g. = image_tag or = link_to. 

 

For if and else statements, the -sign replaces the ERB <%   %>.  This apparently is for code that is intended to be hidden.

Read More






Footerfull