Check out my presentation for “Ruby for Java Developers” on Slideshare: Ruby for Java Developers from Robert Reiz
Category Archives: Ruby
Config file in Ruby on Rails
There are a bunch of config files in a Ruby on Rails app. The most popular ist the “database.yml” config file. This is for configuring the database connection in 3 different environments. Assume you want to have your config file, in the same style as the database.yml file. Where you can configure some program logicContinue reading “Config file in Ruby on Rails”
Multiple Heroku Accounts on one machine
To have multiple accounts on Heroku is no fun. Specially not if you are a developer and you have to push multiple apps into multiple heroku accounts. The problem is that the heroku toolbelt authentification is based on ssh certificates. If you create your very first heroku app on your machine, heroku will take yourContinue reading “Multiple Heroku Accounts on one machine”
Rails 3.X – “You are being redirected” – “406 Not Acceptable”
I used “redirect_to” in a controller to redirect the user to a different page. And I always got a: “You are being redirected” In the Browser. And a “406 Not Acceptable” in the console. I googled the whole day for this issue. In the end I found out that the problem was a new actionContinue reading “Rails 3.X – “You are being redirected” – “406 Not Acceptable””
MongoID Lessons Learned
I am using MongoID to access MongoDB from a Ruby on Rails application. It is a good library. But there are some things I found out during the project, I want to share here. Nothing bad. Just some behaviors should now about. Case Insensitive Search There are different ways to write queries with MongoID. One pretty coolContinue reading “MongoID Lessons Learned”
SSL in Ruby on Rails
There is a very good support for SSL in Ruby on Rails. Assuming that you installed a valid SSL certificat on your production server or on your PaaS Provider (Heroku), it is very easy to switch all links to https. If you want to force every link to https, just add this line to yourContinue reading “SSL in Ruby on Rails”
Cron Jobs on Heroku
Heroku is an App Engine for Ruby on Rails … and other Languages and Frameworks. Heroku is running your application and you don’t have to care about hardware or IT-Infrastructure. It is one abstraction layer above the Amazon Cloud EC2. First of all, there are no cron jobs on Heroku. Because it is an AppContinue reading “Cron Jobs on Heroku”
The Power of Indexes
I am working on VersionEye.com and in the last days we had some performance issues. I added some new data to the database and to the views. The rendering of the package detail pages tooked sometimes up to 5 seconds. And because the UI is programmed with Ruby on Rails, some people told me: “YesContinue reading “The Power of Indexes”
Dependency Wheel for RubyGems
I just released a new Feature for VersionEye. For RubyGems Pages with more than 3 dependencies a JavaScript Engine is rendering the recursive dependencies as an interactive wheel. For Ruby on Rails the dependency wheel looks like this here: Let me know what you guys think.
Postmark InvalidMessageError
If you get this ERROR her in a Ruby on Rails app: Postmark::InvalidMessageError: Provide either email TextBody or HtmlBody or both That usually means just that you have a misspelling somewhere in your code. Rails is working with a lot of conventions. In my case a directory was miss spelled. After I fixed the spellingContinue reading “Postmark InvalidMessageError”
Handling Routing ERROR in Rails 3.2
Routing Errors are caught if somebody is calling a path on your app which is not existing. This how I handled it. I just added this line to the end of the routes.rb match ‘*path’, :to => ‘page#routing_error’ It is important that this is on the bottom of the routes.rb. That just means, if noContinue reading “Handling Routing ERROR in Rails 3.2”
RVM
RVM is an environment manager for Ruby. With RVM you can handle different versions of Ruby and different gemsets on the same machine. With this command you can install the tool on your machine. bash -s stable < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer) source ~/.bash_profile If you want to install a special ruby version on your machine,Continue reading “RVM”
Failed to connecto to primary node
If you try to connect to MongoDB Replica Set via MognoID and you get this error message here: /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/repl_set_connection.rb:165:inconnect’: Failed to connect to primary node. (Mongo::ConnectionFailure) from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/repl_set_connection.rb:500:insetup’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongo-1.5.2/lib/mongo/repl_set_connection.rb:144:in initialize’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config/replset_database.rb:24:innew’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config/replset_database.rb:24:in configure’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config.rb:316:inconfigure_databases’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config.rb:119:in from_hash’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid/config.rb:136:inload!’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/mongoid-2.3.4/lib/mongoid.rb:147:in load!’ from /Users/reiz/workspace/versioneye/versioneye/config/application.rb:33:inclass:Application’ from /Users/reiz/workspace/versioneye/versioneye/config/application.rb:18:in <module:Versioneye>’ from /Users/reiz/workspace/versioneye/versioneye/config/application.rb:17:in’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:52:in require’ from /opt/local/lib/ruby1.9/gems/1.9.1/gems/railties-3.1.0/lib/rails/commands.rb:52:inblock in ‘ fromContinue reading “Failed to connecto to primary node”
Rails + MongoDB ReplicaSet Configuration
This article shows how to configure a Ruby on Rails app for a MongoDB ReplicaSet. How to set up a MongoDB ReplicaSet I described here: MongoDB ReplicaSet Tutorial. And how to configure Rails to work together with MongoDB is described here: Rails + MongoDB Quickstart Tutorial. If you want to connect to a ReplicaSet youContinue reading “Rails + MongoDB ReplicaSet Configuration”
MongoID read_secondary deprecated
OK. If you are using Rails + MongoID and you get this error message here: read_secondary options has now been deprecated and will be removed in driver v2.0. Use the :read option instead. Than you just have to change your configuration. Just replace “read_secondary” with “read”.
Rails + MongoDB Tutorial. Quickstart.
This is a Quickstart Tutorial for Rails + MongoDB. Ruby on Rails and MongoDB, a document based database, is a pretty good fit. It is very easy to integrate MongoDB with Rails. If you want to know how to install MongoDB, check out this article here: Installing MongoDB on Mac OS X Lion. Or thisContinue reading “Rails + MongoDB Tutorial. Quickstart.”
Running Unicorn as a Service on Debian Linux
Unicorn is a very fast app server for Ruby on Rails. You just have to go to the APP_ROOT and type in “unicorn_rails”. And your app is running. The problem with that is, if your server reboots your app is down. And you have to start it again by hand. That is not so cool!Continue reading “Running Unicorn as a Service on Debian Linux”
Installing Ruby 1.9.X on Debian Linux
It is pretty easy to install Ruby on Debian. Just execute this as root: apt-get install ruby1.9.1 That’s it! Depending on that GEMs you want to install you should install this here, too. apt-get install make bcrypt libxml-ruby1.9.1 libxml2-dev libxslt-dev libpq-dev g++ Your GEMs are at “/var/lib/gem/1.9.1/”. You should add this here your path: /var/lib/gem/1.9.1/bin That’s it.
Integration Tests with RSpec
RSpec is a Test Framework for Ruby! And RSpec is just awesome! It is the best Test Framework I know. Add this 2 lines to your Gemfile to the test group and the development group. gem ‘rspec-rails’, ‘2.8.0’ gem ‘webrat’, ‘0.7.3’ Webrat is a browser simulator. With RSpec and Webrat you can write integration tests and test the UI ofContinue reading “Integration Tests with RSpec”
RSpeck before after
RSpec is a Test Framework for Ruby! And RSpec is just awesome! It is the best Test Framework I know. Add this 2 lines to your Gemfile to the test group and the development group. gem ‘rspec-rails’, ‘2.8.0’ gem ‘webrat’, ‘0.7.3’ Webrat is a browser simulator. With RSpec and Webrat you can write integration tests and test the UI ofContinue reading “RSpeck before after”