Tag ‘Rails’

Using Raw SQL snippets to create Thinking-Sphinx Indexes

We have used Thinking-Sphinx in several projects to implement search engines. Thinking-Sphinx is a wrapper in Ruby to use ActiveRecord with Sphinx. But in the project I’m working right now I had to solve a different problem: the user should be able to search for formatted values, however without using the formatting characters, i.e, suppose a field containing 111.444.777-35, the user should be able to find it searching for 11144477735 (or a substring of it).

The default behaviour for Thinking-Sphinx is to index the exact values for each column it scans, but we can by-pass it. The Thinking-Sphinx index definition allows us to use raw SQL to define which values should be indexed for each attribute. In my case, I used the native PostgreSQL regular expressions functions to get rid of the punctuation characters, indexing only the “clean” version of each value. My database column is called “entity_number”:

define_index

Continue reading

How to send a large quantity of email in Rails, using ar_mailer

Radu Cojocaru

email-newsletterSending a large number of emails is not an easy task. It can take a lot of time so you need to do it asynchronously. Also, if you are on a shared hosting, you might be limited to a certain number of emails per hour, so you need to divide your list of email addresses in batches and send them at certain intervals.

There’s a plugin that can help us with this: ar_mailer.

This plugin adds a new deliver method to ActionMailer::Base :activerecord. In this delivery method, emails are not actually delivered, they are stored into a database table. A ruby script ar_sendmail can then be run (in a cron job) in order to send the emails saved in the database.

Step by step intructions on how to use the plugin:

1) Install the plugin

./script/plugin install git://github.com/adzap/ar_mailer.git

Add following line to config/environment.rb:

config.gem "adzap-ar_mailer",

Continue reading

How long will it take to understand Rails 3 in and out?

Brad Midgley

According to David Heinemeier Hansson, you will never understand it all. Case in point? David himself.

That was the gist of his answer to how a new change to the way rails 3 renders actions in the browser would be handled for older browsers.

DHH gets involved in the parts he cares about and doesn’t worry about the exact details that have been delegated to someone else. He says we should not worry about knowing the whole framework because he doesn’t either. We don’t need to live up to an impossible standard.

Continue reading

We’re hiring! Ruby on Rails/Rhodes developer

Mauro Dalu

job-opening-hire-rails-rhodes-developerOffshore software developer position using Ruby on Rails and web technologies to build web applications for desktop browsers and targeting mobile devices. Also using Rhomobile to make native mobile applications.

Candidate should be a remote worker, must use an Intel Mac running OSX 10.5 or 10.6, should have strong communications skills, good written and spoken English. Availability on IM or Skype required during work hours.

Continue reading

Linux kiosk

Brad Midgley

I recently did some maintenance on a linux-based kiosk project. It runs linux and has a rails application serving content. Firefox is running in a kiosk mode and there is no keyboard or mouse present.

In adding a touchscreen from a different vendor, I found some details that can help make a kiosk application more responsive to touchscreen taps.

If you use linux in a touchscreen implementation, I recommend staying away from linux drivers offered by the vendor if possible. These were very out of date and X refused to load them. Use evtouch if possible. Install the package:

apt-get install xserver-xorg-input-evtouch

Note that most of the parameters to the driver are meant to discourage it from giving us complicated mouse emulation behavior like mousovers, middle/right clicks, dragging, etc. It needs to be just the simplest it can be for kiosk operation. People will push buttons too long, unintentionally try to drag

Continue reading

Using cucumber and webrat for remote web testing

Cucumber and webrat serve as a powerful combination of tools for testing your web applications, but in its most common mode webrat can only test your application locally. Is it possible, you may ask, to use webrat to test a remote web site? The answer is yes, with a little tweaking. Webrat has a configuration option that tells it to use mechanize (a screen-scraping tool for ruby) instead of the built-in rails view testing system.

Continue reading

RadiantCMS customized

Brad Midgley

Kolob Canyon greenery

We are working on a very interesting project right now that allows us to adapt RadiantCMS to serve several different functions in a big picture system.

Radiant is a powerful content management system that has very good design for factoring out redundancy in your web content. Think of the Don’t-Repeat-Yourself principle applied to the web content, where we unfortunately put up with duplication far too often.

I was impressed with the hierarchy of web content in Radiant: layouts, snippets, ways to bring this together with tags. The tags reminded me of JSP work in past projects, but in this case it feels like borrowing a good idea and making it do more.

The extension design is interesting and allows us to focus customization work outside the core of the system. There are also a lot of interesting extensions already available.

Radiant runs

Continue reading

best railsconf title

Brad Midgley

The best title had to be When to Tell Your Kids About Client Caching. Parents might identify more with this. Interesting stuff in any case.

Continue reading

Ruby performance work

Brad Midgley

Railsconf had several performance-related talks. This one went over a lot of interesting territory.

  • Who knew the Date class performed so badly?? Use equivalent ops in Time or get date::performance
  • Use String::<< instead of String::+=
  • Tune your custom sql with virtual attributes

It’s surprising that things we might not think are performance issues are problematic in ruby. One reason to optimize after you gather metrics that identify problem areas.

rowing

(Image courtesy of rowingbike.com)

Continue reading

RubyMine

Brad Midgley

During his talk at railsconf, Gregg Pollack showed off Jetbrains Rubymine, an awesome IDE for ruby & rails. I wouldn’t be surprised to find out Jetbrains had a spike in their downloads coinciding with the talk. It is a nice IDE. I was happy to see it includes git support out of the box (I only had to set the path to the git executable).  I like the web preview for rails applications. On the downside, I had difficulty opening a large project. I had to stick to more typical rails applications.

It might be time for me to try eclipse again and see how RDT stacks up now.

Contact your usergroup and you can get a deal with Jetbrains to get discounts if you go that route.

Continue reading