Tag: Ruby

RVM, Ruby 1.9.3-p194, ruby-debugger and “You need to install ruby-debug” on Ubuntu 11.10

Recently I've been upgrading my RVM and Ruby versions. After upgrade I've encountered a problem connected to ruby-debugger. When starting Rails server I always ended with such a message:

You need to install ruby-debug to run the server in debugging mode. 
With gems, use 'gem install ruby-debug'

# Edit: this solutions fixes also this problem:

cannot load such file -- zlib

Ruby-debbug doesn't work to well with Ruby 1.9, so I use following combination in my gemsets:

group :development, :test do
  gem 'linecache19', :git => 'git://github.com/mark-moseley/linecache'
  gem 'ruby-debug-base19x', '~> 0.11.30.pre4'
  gem 'ruby-debug19'
end

Until now, it worked really well, but after the upgrade, the "You need to install ruby-debug" message kept showing again and again (even when the gems from list above were installed). To fix this issue, you need to run following commands:

rm -rf $rvm_path/usr
rvm pkg install zlib

# Posted in 5 lines instead of 1 for better visibility
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev 
sudo apt-get install curl git-core zlib1g zlib1g-dev libssl-dev
sudo apt-get install libyaml-dev  libsqlite3-0 libsqlite3-dev sqlite3
sudo apt-get install libxml2-dev  libxslt-dev autoconf libc6-dev 
sudo apt-get install ncurses-dev automake libtool bison subversion

rvm reinstall 1.9.3-p194

After successful Ruby version reinstall, you should be able to run ruby software with debugger enabled.

# Update
Looks like, you can (as guys suggested in comments) debugger instead of ruby-debugger, however the method above fixes also problem with:

cannot load such file -- zlib

Rails routes: limiting access to application parts from certain domains (hosts)

Sometimes we want to handle different parts of a single application from different domains. A good example of such an approach is when we have a scope containing our API. Wouldn't it be great if it could be served from a different domain than the rest of the application? Of course yes! Approach like this (separating the API from the rest of the app) is used in several popular web applications. For example in Twitter. The app is under twitter.com and the API lies under the api.twitter.com url. When you have a smaller Rails app, probably you maintain the API-part and the user-part in one Rails project. The separate domains approach allows you to easily move to the two different apps, when the time comes.

So, how to limit access to the app parts based on the domain? Let's use constraints. Let's assume, that we have a scope called :api and the scope called :ui. Each scope represents a module in our app:

scope :module => :api do
  # Some resources and additional routes here
  # Api::SomeController...
end

scope :module => :ui do
  # Some resources and additional routes here
  # Ui::SomeController...
end

To make it domain-accessible we just need to wrap it with a block like this one:

constraints(:host => 'my_domain') do
# Routes here
end

where the my_domain is a domain that should be used with our app part. So for the example above, it would look like this:

constraints(:host => 'api.example.com') do
  scope :module => :api do
    # Some resources and additional routes here
    # Api::SomeController...
  end
end

constraints(:host => 'my.app.example.com') do
  scope :module => :ui do
    # Some resources and additional routes here
    # Ui::SomeController...
  end
end

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑