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.

Self and Class Methods versus Instance Methods in Ruby

Self in ruby

Self tells Ruby that this is a method that acts on the Class and not on an instance of the class.  You can see a great example in the screenshot.  In the first, I define a class method, using Self.  Self is one way to define a class method.  Another two ways are, def Class.new_method or def Class << new_method.  When I run the program, the output of puts Test.output shows a capitalized „Test.“  The output method has worked itself upon the ABCD variable INSIDE of the Test Class.

 

But what would happen if I tried to run Test.output without having defined a Class Method using self?  Well then, the method would fail.  But where it would succeed?  On an INSTANCE of Test.  Because now I’ve actually written an Instance Method.  And that’s what you see in the Test2 Class. 

Read More

The guts of Rails Scaffolding

A scaffold in Rails is a full set of model, database migration for that model, controller to manipulate it, views to view and manipulate the data, and a test suite for each of the above.

Read More

Active Record Pattern

An active record pattern is a pattern for a type of object related to databases.  It was first named in 2003.  The interface of such an object would have the basics of database stuff: functions such as insert, update and delete, plus properties that correspond more or less directly to the columns in the underlying database table.  

 

Read More

||= Conditional Assignment Operator

Scannen 2

Conditional assignment is when you want to assign a value to a variable (x = 10) but ONLY if the variable is unassigned.

It combines the "or" logic operator (||) and the normal assignment (=) operator.

The following would show the results:

 

favorite_book = nil

puts favorite_book

 

favorite_book ||= "Cat's Cradle"

puts favorite_book

 

favorite_book ||= "Why's (Poignant) Guide to Ruby"

puts favorite_book

Why do we USE conditional assignment?

Well, if we didn’t have conditional assignment, we would have to ask whether a variable was empty first.  

If variable.nil? 

variable = 4

end

 

With conditional assignment we can just say, 

 

variable ||= 4!

When set to nil favorite_book can be set to "Cat's Cradle", because nil in Ruby means nothing.  But if you try to use conditional assignment to set favorite_book after that to "Why's (Poignant) Guide to Ruby" it won't work!  

 

Try running the code in the screenshot to see!

Read More

Setting Up S3 With Heroku

Image

Setting Up S3 With Heroku

Create buckets, both for your local and production environments, e.g.

stoichacks-loc

stoichacks-prod

Go to S3 Permissions, 

Inline image 9

 

Read More






Footerfull