High Tech Sorcery

Ruby On Rails

Researching Redis on Rails

by on Jan.08, 2012, under Ruby On Rails

I’ve been researching how good a fit Redis might be for a project or 2.  One project needs a memory based key-value store generally without persistence, which would seem to suggest memcached.  However, there may be times where persistence across reboots may be desirable and Redis’ atomic operations and data types may also be useful.  Here’s some links I’ve been checking out:

Leave a Comment more...

how to disable Rack::Cache in Rails 3.1

by on Sep.13, 2011, under Ruby On Rails

Couldn’t find this anywhere but what I found worked was to put this in config/application.rb:

    require 'rack/cache'
    config.middleware.delete Rack::Cache

This did fix the issue that sent me to this, as many people are likely to run into. The issue was that since Rack::Cache uses the default Rails FileStore that lots and lots of small files were being created in lots and lots of directories.  I don’t think Rack::Cache offers me much for this application, but if it did I would look into switching from a file store to a memory or memcached store.

1 Comment :, , , , more...

Fixing netbeans in ubuntu

by on May.20, 2011, under Development, Ruby On Rails

Netbeans has some issues in Ubuntu 10.10 and 11.04.  One of the most serious is that javascript syntax highlighting does not work.  Another is that Rails 3 applications do not run or debug correctly.  I found the solution to be going to “Tools – Plugins -Settings” and enabling the “Netbeans” update center.  Then by going to “Updates” and clicking “Reload Catalog” I got an update for the update system.  After that was installed an netbeans was restarted I got a lot more updates for plugins (15 or so).  Once updated everything seemed to work as it should.

More information:

1 Comment more...

upgrade a rails app from rails 2 to rails 3

by on Apr.24, 2011, under Ruby On Rails

Just a few notes on a recent upgrade with a rails project that was fairly young thus did not have a lot of issues moving to rails 3.

(continue reading…)

Leave a Comment more...

problems upgrading devise in an rails 2 to rails 3 migration

by on Apr.22, 2011, under Ruby On Rails

I ran into some problems upgrading devise from 1.0.x to 1.3.x.

  • to use passwords besides bcrypt you have to made 2 changes:
    • in config/initializers/devise.rb
      • config.encryptor = :sha1 (for devise 1.0.x compatibility)
    • in User model (or whatever model calls devise)
      • call devise with both :database_authenticatable and :encryptable
    • you can tell you have issues with this if you see errors like BCrypt::Errors::InvalidHash or “invalid hash”
  • browser validation prevents sign in with something other than email
Leave a Comment more...

Determining if a string is a float

by on Mar.19, 2011, under Ruby On Rails

Using to_f has the problem of returning 0.0 for invalid strings.  So for a project I needed to know if a string was a valid float or not and came across this helpful page: ruby on rails – Determine if a string is a valid float value – Stack Overflow.  My favorite option was this:

 


class String
def valid_float?
# The double negation turns this into an actual boolean true - if you're
# okay with "truthy" values (like 0.0), you can remove it.
!!Float(self) rescue false
end
end

Leave a Comment more...

Accessing MS SQL Server from Rails without ODBC

by on Mar.18, 2011, under Ruby On Rails

I found myself looking through the code for activerecord-sqlserver-adapter and noticed a new mode called “dblib”.  It turns out this mode can be used when using the tiny_tds gem along with FreeTDS to avoid using ODBC altogether.  I decided to try it out on a project and have found it to work very well so far.  The update_sql call no longer has to make a call to get the number of affected rows, something which was slowing down the code significantly.  I don’t have many benchmarks yet but it looks like performance is up or has remained constant across the board.  I’m not sure if there are any problems that might come up, certainly TinyTDS is a relatively new project.  But for now I’m enjoying not having to use ODBC and hopefully this will continue to work well moving forward.

Leave a Comment more...

Ruby regexp surprise: \w is not equivalent to [0-9A-Za-z_]

by on Mar.17, 2011, under Ruby On Rails

Despite ample documentation to the contrary I was surprised to learn that by default ruby matches \w to all unicode characters.  This lead to some strange results in one of my apps where unicode quotes were present and matching \w.  I found the solution is to use /\w+/n to specify the n kcode rather than the u kcode.  But this was still distressing to find as the default in 1.8.7 and 1.9.2.  It was further complicated by trying to get information.  The following websites all report that \w is equivalent to [0-9A-Za-z_]:

According to these links, this behavior is spec but not documented anywhere:

Leave a Comment more...

Rails marshal data too short

by on Mar.15, 2011, under Ruby On Rails

I ran into an error when trying to save an object in flash between Rails actions.  I’m still not sure why marshal data too short happened as the session storage is mysql using the text type which should be 64kb.  I can’t imagine the object taking more size than that but it would be worth checking.  I resolved the issue by not storing the object but other options would be figuring out why the object is so large (Marshal.dump(object) maybe) or switching to mediumtext type which has a limit of 16MB.  To do this via a migration can be found here:

ruby on rails – marshal data too short!!! – Stack Overflow

Leave a Comment more...

Working with devise for Rails authentication

by on Feb.27, 2011, under Ruby On Rails

I’ve begun using devise for authentication for my various Ruby on Rails applications.  It is based on warden which seems a sensible choice.  There is also a fairly large community and active development.  Devise plays nice with authorization libraries such as CanCan and can be integrated with OmniAuth for oauth/oauth2 authentication.  I’ve run into a number of issues so I thought I would track some of the useful links that have helped me out.

(continue reading…)

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Blogroll

A few highly recommended websites...