Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial


Is anyone else simply failing to see the logic of Ruby on Rails?

This is so depressing. I've spent months on Ruby on Rails, read three books on it, and spent endless nights on stack overflow quering everything.

I completely and utterly understand languages like javascript with jquery. Completely, because after a few weeks, you start to see the logic. How web elements are refrenced, how to chain functions together, how to pass parameters into functions, it all makes perfect sense.

I just can't see it with Ruby on Rails. At all. I mean look at this:

require 'test_helper'

class UserMailer < ActionDispatch::IntegrationTest
test UserMailer
test "invite" do
    #send the email, and then test that it got queued
    email = UserMailer.create_invite('julian@designimperial.com', 'jimbolooney62@gmail.com', Time.now).deliver
    assert !ActionMailer::Base.deliveries.empty?

    #test the body of the sent email contains what we expect
    assert_equal ['julian@designimperial.com'], email.from
    assert_equal ['friend@example.com'], email.to
    assert_equal 'You have been invited by julian@designimperial.com', email.subject

    assert_equal read_fixture('invite').join, email.body.to_s

It's an integration test. I understand what it does, and what the code does, but not in great depth.

require 'test_helper' Don't know what that means. Don't know what "require" is. Is it a method? If it's a method why isn't the string "test_helper" passed in like this: require('test_helper')

class UserMailer < ActionDispatch::IntegrationTest


Don't know what a class is. Don't know what < means. Why are there two colons between ActionDispatch::IntegrationTest? Why? Are they symbols? What does it mean?

email = UserMailer.create_invite('julian@designimperial.com', 'jimbolooney62@gmail.com', Time.now).deliver

I slightly understand that I suppose. Somehow we can access methods inside "UserMailer", create an invite, and pass in two email addresses and a time stamp, deliver it, and set it to the variable "email".

But then, here is my UserMailer mailer, which is what I assume is what the test is dealing with, and where is the invite method? And the deliver method? Where? What is going on?

class UserMailer < ActionMailer::Base
  default from: "from@example.com"
  def welcome_email(user)
    @user = user
    @url = "http://example.com/login"
    mail(to: @user.email, subject: "Welcome to my awesome site!")

I'm getting so depressed.

assert !ActionMailer::Base.deliveries.empty?

Right, so this is asserting that the action mailer isn't empty? Because of the exclamation mark? But I don't really understand any of it.To my mind, we have this !ActionMailer::Base. I haven't git a clue what it is. Some vague thing called ActionMailer, that has two colons for no reason joining to a Base. What a Base is I have no clue. But anyway, we call a delieveries method on it, and then we pass an empty? method on it. What delieveries does I don't know, but I assume empty? returns true if the result of delieveries is null, and returns false if the result of deliveries is not null. Again, I'd understand more if the method delieveries was in the mailer!

assert_equal ['friend@example.com'], email.to

I assume assert_equal is a method that "returns a pass" (vague definition I know) to the command line if the two variables passed into it are equal, and returns a failure if they are not equal.

See, this is just what I mean. If it's a method, it should be written like this:


But instead we have this:

assert_equal ['friend@example.com'], email.to

There's no just no logic. Oh yes, let's put one variable inside square brackets (what is that does it make it an array?) the other just floating there, no parenthesis his at all.

Watching these treehouse videos, the instructions could literally making up the code as they go along, from my point of view. It just makes no sense to me. I can't see any structure at all.

I've put so much time into this. If someone could actually explain some of these things, or give a really good book on the matter, or something, I don't know. I understand the concepts of rails, the conventions. I sort of understand routes and views. But the whole thing is just insane.

4 Answers

Patrick Cooney
Patrick Cooney
12,216 Points

Stop. Take a few deep breaths. Ok, let's proceed.

It sounds like you may be having trouble with some of the basic principles of Object Oriented Programming. The rest of your issues seem to be a matter of syntax which can vary greatly between languages. I highly recommend you take a look at the Ruby Foundations Deep Dive before you continue trying to learn RoR. You don't have to know ruby to use RoR but it sounds like in your case it would be beneficial to learn the language first.

Just a syntax sugar. Nothing personal =)

You're hitting on why I don't like programming beginners to mess with Rails or possibly even Ruby. The amount of syntactic choice is both refreshing and confusing. The other problem is that even if you deeply understand MVC philosophies, there are conventions that Rails takes that break strict MVC philosophy. It's also clear you're missing key syntactic points of Ruby itself due to some of your confusion. Please try to learn more about Ruby before continuing on Rails. Rails is weird enough to deal with without basic confusion over the way Ruby works.

I recommend the Pragmatic Programmers series due to their affordable price point on eBooks and unlimited version upgrades, both the Ruby and the Rails one: http://pragprog.com/book/rails4/agile-web-development-with-rails-4 and http://pragprog.com/book/ruby4/programming-ruby-1-9-2-0

Julian, the best advice I got is:"You have to learn ruby before you start working with Ruby on Rails." You mentioned that you are familiar with javascript and Jquery. When you come to Ruby, you have to put aside some habits you picked up from other languages so that you can learn the:"The Rails Way." You come across that term a lot. I know javascript, C#, java, jquery, etc. I made the mistake of starting with Ruby on Rails. I was lost. I had to go back and start with Ruby. Now I'm on a solid foundation. I'm new to this website so I can't comment about the ruby videos on here yet. I hope these words were helpful.