• Home
  • Log In
  • Sign up
← Previous 1 2 3 4 5 6 7 8 9 10 Next →

TicTacToe Rails Mailer Bug

Mon Jun 17 18:07:06 2013

I had a bug in my TTT Rails app. When I try to send out email, I get

NameError: ActionMailer is not missing constant Base!
  load_missing_constant at /Users/ckim/.rvm/gems/jruby-1.7.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:494
          const_missing at /Users/ckim/.rvm/gems/jruby-1.7.1/gems/activesupport-3.2.13/lib/active_support/dependencies.rb:192
.
.
.

It turns out that at one point I created a mailer called mail.

# don't do this

$ rails g mailer mail

Once I deleted that file (app/mailers/mail.rb), my email starting working again.


Show

Tic Tac Toe Kata in Ruby Using TDD

Sun Jun 16 13:31:09 2013

I've been practicing TicTacToe in Ruby using TDD for the past few days. I finally got it down to under an hour (50 minutes actually). I posted a video of me coding it and I sped up the video about 3x so it comes in a little over 14 minutes.

I started doing the TTT when I boarded the plane for my Chicago trip (Tues). The flight lasted 2 hrs. I managed to write a TTT game in 1 hr 50 minutes but didn't finish the user interface. The next day (Wed), I wrote it again, it took about the same amount of time, but I was able to finish the interface. On the flight back (Sat) I managed to do it in 1 hr 15 minutes. Today (Sun) I got it down to 50 minutes. I uploaded it to YouTube (my first video). It's actually entertaining to watch it.

I thought of adding audio, but the tests seem to explain what I'm doing pretty well. The user can pause the video and figure it out themselves since the code is right there and each method is pretty short.

I've put the source code on Github.


Show

CoffeeScript

Tue Jun 11 09:02:23 2013

I've always wanted to try CoffeeScript ever since I saw it on Railscast. I finally got my chance. Luckily it comes built-in for Rails 3, but I didn't know how it worked. At first I thought I needed to compile and downloaded the coffee compiler. It turned out to be useful to have. Rails does not give good error messages if there is a problem in the coffee script, so I run it through the compiler and it'll give me a better idea of what's going on.

Installing CoffeeScript. CoffeeScript is a Node.js module. Node.js is a javascript interpreter you can use outside of the browser. To install using Homebrew use

$ brew install node
$ sudo npm install -g coffee-script

and put this in your ~/.bashrc file

PATH="/usr/local/share/npm/bin/:$PATH"

You can use the coffee command to compile your coffeescript.

Don't neeed guard. I installed guard-coffeescript but I found I didn't need it. You don't need to compile it because Rails will automatically do it for you using the asset pipeline.

The language. Coffeescript is somewhat like python in that indents matter. if then does not need an end. You don't need curly braces or semicolons. Sometimes you don't need parentheses. Functions are defined using ->. So far these are simple translations that make your code smaller. You get power when you find out about the for loop. If you go to the coffeescript website, they have a really great overview of the language with lots of examples. You can even use the coffeescript interpreter directly from the browser. I found that useful when I'm developing some tricky coffeescript. You can immediately see any errors as you type then.

It's a bit frustrating when you make some modifications to your code and it either just doesn't work or you get an incomprehensible error. You end up looking at the resulting javascript for clues. The trouble is worth it because some of the powers of the for loop and parameter handling (you can have default args).

All in all, it's worth looking into. Probably the best way to use it is by converting an existing javascript code and cleaning it up.


Show

Spork Broken For Cucumber On JRuby

Wed Jun 5 19:52:15 2013

Spork was almost running on JRuby, but it's completely broken. I ran my experiment where I created a new MRI rails application called foo. I modified the gemfile to include

 group :test do
  gem 'spork-rails'
  gem 'cucumber', '1.2.5'
  gem 'cucumber-rails', :require => false
  gem 'guard'
  gem 'guard-spork'
  gem 'guard-cucumber'
  gem 'database_cleaner'
end

I run bundle install.

I set up cucumber with rails g cucumber:install.

I set up spork with spork cucumber -b. I modify the features/support/env.rb file.

I set up guard with:

guard init cucumber
guard init spork

I edit the Guardfile so that cucumber runs with :cli => '--drb'.

I create some dummy feature files and I run guard. This works perfectly on MRI Ruby, but JRuby acts really flakey. First thing you notice is the error message:

16:02:45 - INFO - Running all features
SocketError: bind: name or service not known
        bind at org/jruby/ext/socket/RubyUDPSocket.java:160
  initialize at /Users/ckim/.rvm/rubies/jruby-1.7.1/lib/ruby/1.9/rinda/ring.rb:35
      (root) at ring_server.rb:7

Second thing you notice is that the color is gone if it runs your features. Sometimes it decides not to run it.

If you run cucumber on the command line it complains that there is no DRb

euler:jfoo ckim$ cucumber --drb
Using the default profile...
file:/Users/ckim/.rvm/rubies/jruby-1.7.1/lib/jruby.jar!/jruby/java/java_package_module_template.rb:11 warning: `eval' should not be aliased
WARNING: No DRb server is running. Running features locally:

But you can see that it connected from looking at the spork output log.

I did the same thing using MRI Ruby and everything worked. No problems at all. I'm beginning to hate JRuby even though there's nothing with with JRuby itself. The gem support really sucks.

I tested RSpec and that seems to work fine on JRuby so I'll need to convert my test over.


Show

TTT Rails Problems - Livereload, CSS

Tue Jun 4 10:05:18 2013

One thing I hate about JRuby is that you keep encountering broken gems. Livereload is one of those. I have guard running and installed livereload for guard and the browser. It looked like it should work because I saw the guard message that the browser had connected. As soon as I make a change, it breaks. Of course the next step is to set up a dummy MRI ruby instance and set up livereload again to see if it's a problem with my setup. I do that and it works fine. No problems. I made sure I did the exact same steps in JRuby, even uninstalling and reinstalling gems. It still didn't work. After an hour or so, determined that the gem is broken. I tried to see if there were other gems, perhaps a jruby version. I found one on Github, but it too was broken. I wasted a lot of time on this. This is one major drawback to using JRuby.

Another problem I had today was with CSS. Let's say you had

<!DOCTYPE html>
<html>
  <style type="text/css" media="all">
    #whole {
      width: 100%;
      height: 100%;
      background-color: red;
    }
  </style>
<body>
  <div id="whole"></div>
</body>
</html>

You'd expect to see a flood of red on your screen. Instead you see nothing. If you take away the <!DOCTYPE html>, then it works. If you keep the doctype, you can also get it to work by setting the html and body sizes.

<!DOCTYPE html>
<html>
  <style type="text/css" media="all">
    html, body {
      width: 100%;
      height: 100%;
    }
    #whole {
      width: 100%;
      height: 100%;
      background-color: red;
    }
  </style>
<body>
  <div id="whole"></div>
</body>
</html>

Seems like <!DOCTYPE html> defines the body and html to have height zero until there is content. This one issue took a while to figure out because I kept stripping my HTML down until it was basically nothing.

One good thing was I got my project going along. I incorporated Alejandra's images and the background for the website. I accidentally deleted the files she had created for me, but I remembered that I had Time Machine and went back and fetched it. It was the first time I used Time Machine. Now it has become part of my toolset.


Show
← Previous 1 2 3 4 5 6 7 8 9 10 Next →