Thursday, October 28, 2010

Authlogic for Rails 3

I forked Authlogic because I was tired of the Rails 3 deprecation warnings in my project. The forked project is Rails 3 compatible. I just made a few minor changes to how Users are saved and changed some scopes. Enjoy!

gem "authlogic", ">=2.1.6", :git => "http://github.com/perry3819/authlogic.git", :ref => "044b20289316ef6e338d"

Labels:


Convert your Sass

sass-convert --from sass2 --to sass --in-place --recursive app/stylesheets/.

will convert Sass 2 to Sass 3

Labels:


Memcached undefined class/module in development environment

I had some trouble tracking down the cause of a undefined class/module error from the memcache client so I thought I would share my findings.

The memcache-client uses the ruby core Marshal.load to retrieve the cached values from the memcached server. In this context, Marshal.load does not have the benefit of the Rails class-loader, which results in the above error.

To fix:

  1. Set cache_classes=true. This is probably already set to true in every environment except development. The class will have already been cached before the Marshal.load if caching is turned on.
  2. Make sure that cached classes are referenced in the controller before cache retrievals are attempted. This is usually accomplished with a before_filter in the application_controller.rb
  3. Leave cache_classes=false and set the cache_store to a server:port that is not running memcached. When rails encounters the caching block, it will try to fetch from cache and find nothing because it cannot connect to the memcached server. It will then execute the code inside the cache block successfully.


Option 1 is is not desirable because server restarts are required for clients to see updated server classes. I really don't like option 2 because we are adding development-only code to production code. I like option 3 because I don’t need memcached running in development mode.

The relevant parts of my development.rb:

config.cache_classes = false

config.cache_store = :mem_cache_store, '127.0.0.1:11211', {:namespace => "dev"}


Labels:


Thursday, November 12, 2009

MySecrets


I developed MySecrets to manages my personal secrets/passwords. I had a lot of fun doing BDD with cucumber. Pickle works very nicely with Machinist to reduce step definition code. I used authlogic for authentication and formtastic to reduce the boiler plate code in my views.

I had some trouble integrating cucumber, pickle, machinist, and authlogic. A user has 0 to many secrets and secrets are protected by authlogic. So cucumber features that needed to add secrets and validate them were a little tricky.

This scenario creates a user, login in, creates a secret, shows the secret, and finally validates the secret.


The show pages are handled with a polymorphic_path.


The actual user creation and login steps are handled here.


The secret is validated with:


All of the coded can be found at http://github.com/perry3819/mysecrets

Labels: , ,


Monday, October 26, 2009

Interval Rails Caching

Feedpoint (source) is a blog aggregator written with Ruby on Rails deployed on a linux server. It retrieves RSS content from blogs and displays them sorted by date at http://feedpoint.hertler.org. Retrieving the RSS content is an expensive step and caching is needed to speed up HTTP requests. Google searching for a way to expire page caching on a timed interval did not yield promising results so I developed a very easy custom strategy through the use of Linux cron jobs.

The Rails code for the page caching is in home_controller.rb.



caches_page and expire_page  are ActionController methods. caches_page caches the the :index and :planet_redpoint actions and expire_page expires them.

With this setup, http://feedpoint.hertler.org/home/ will load the :index into page cache and http://feedpoint.hertler.org/home/expire_cache will expire the cache. At this point, monkeys could be trained to navigate to the expire_cache URL every ten minutes or a cron job could be set up. This post will focus on setting up the cron job.

The cron job was configured by entering crontab -e from a terminal and then adding the following line:


This job uses cURL to call the expire_page action every ten minutes. Good cron tutorials are all over the web and beyond the scope of this post.

One added benefit of this approach is that if a blogger is anxious for a recently posted blog to show up on the world famous http://feedpoint.hertler.org site, it can manually be refreshed right away!

Labels: ,


Monday, August 10, 2009

Install mysql gem on OS X 10.5

I had a little trouble installing the mysql gem on OS X 10.5 this morning so I thought I would post the solution.

1) Download the mysql binaries from apple http://support.apple.com/kb/TA25017?viewlocale=en_US
2) Unpack the binaries.
3) sudo gem install mysql -- --with-mysql-config=/usr/bin/mysql_config (be sure to give an absolute path to the config file)
4) done

Labels: , ,


Feedpoint - Rails Blog Aggregator

I finished up the 0.1 release of feedpoint.

Feedpoint is a blog aggregator. Companies may find it useful for showcasing blogs of its employees.

So far, the whole application is written with Ruby on Rails. Additional front-end frameworks are planned including JavaFX and Silverlight.

Privileged users may add new feeds through a web interface.





The main screen displays all of the posts sorted by date.



Labels:


Monday, July 6, 2009

FirstMem - a tool for verbatim text memorization

I have recently spent some time learning Ruby and Rails. When I learn a new language I typically write an easy application so that the focus is not on solving a particularly difficult problem, but on learning the new technology. To learn Ruby on Rails, I wrote http://firstmem.hertler.org. The code is hosted at http://code.google.com/p/firstmem/

As I was writing the code I was constantly shocked at how little code it took to perform complex tasks and how easy the Rails framework is to learn. It almost felt like cheating!


Labels: ,


This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]