Archive for the ‘Ruby/RoR’ Category

Thinking Sphinx attribute filter and negative values

Just wondered why I got no results after executing a search via Sphinx and Thinking Sphinx. The problem was, that I used a negative value in a filter attribute and that Sphinx only supports unsigned integers: Attributes are named. Attribute names are case insensitive. Attributes are not full-text indexed; they are stored in the index [...]

Detecting retarded browsers using Ruby on Rails

Here is a small code snippet to check for retarded browsers in Ruby on Rails: user_agent = request.user_agent unless user_agent[/msie/i].nil? session[:browser] = ‘retarded’ else session[:browser] = ‘normal’ end

xss_terminate – protect your Ruby on Rails code from XSS

Just found this little plugin which is maybe interesting to protect against Cross-site scripting in Ruby on Rails. xss_terminate is a plugin in that makes stripping and sanitizing HTML stupid-simple. Install and forget. And forget about forgetting to h your output, because you won‘t need to anymore. via xssterminate – Project Hosting on Google Code.

RMagick is not accepting ImageMagick version

I just updated couple of gems and got this message while trying to start the WEBrick server: This installation of RMagick was configured with ImageMagick 6.5.1 but ImageMagick 6.5.7-8 is in use. One temporary solution (besides downgrading ImageMagick) is to avoid the version checking by adding RMAGICK_BYPASS_VERSION_TEST = true into your environment.rb for example.

Rails3 screencasts

Some really nice informative screen casts for Ruby on Rails3: rubyonrails.org/screencasts/rails3. For example the new ActionController architecture (AbstractController, respond_to etc.).

Freezing Ruby on Rails applications

To freeze a Ruby on Rails application to a specific version of Rails (e.g: 2.3.5) just execute the following Rake command in your projects root directory. rake rails:freeze:edge RELEASE=2.3.5

Running rake tasks in different environments

To run Rake tasks with Ruby on Rails in different environments, you just provide the necessary variable when starting the task: $ RAILS_ENV=staging rake db:migrate In this case we are starting the migration tasks in an environment called staging. You can of course also provide the standard environments like development, test or production.

Retrieve IP address from host name using Ruby

I just needed to retrieve the IP address for a given host name for a Ruby project. What helped me to achieve this goal was the Socket class. In this example I want to get the IP address for google.com: >> Socket::getaddrinfo(‘google.com’, ‘www’, nil, Socket::SOCK_STREAM)[0][3] => “209.85.129.147″