You are here: Blogsphere Longtail

Rails BlogSphere

BlogSphere

Keep up to date with your favourite Rails bloggers in context.

Read more about how it works


使用 mod_rails 開發 SSL 網頁

by Wen-Tien Chang | about 17 hours ago | Read more

承上一篇使用 mod_rails 當做開發環境,要在 local 開發測試 SSL 網頁,使用 mod_rails 是最方便的選擇,以下是我在自己 Mac Leopard 上的安裝步驟: 1. 首先是產生 SSL Keys # Generate certificate openssl req -new > server.csr openssl rsa -in privkey.pem -out server.key openssl x509 -in server.csr -out server.cert \ -req -signkey server.key -days 365 然後把產生出來的 server.key 跟 server.cert 放到 /etc/apache2/ 下,並 chmod 成 400 唯讀。 2. 編輯 /etc/apache2/httpd.conf,打開 Include /private/etc/apache2/extra/httpd-ssl.conf 3. 編輯 /etc/apache2/extra/httpd-ssl.conf,確認 SSLCertificateFile 跟 [...]

How To Screen Capture (Printscreen) Selective Windows in Mac OS X

by Lim Hong Kiat | about 17 hours ago | Read more

To make a screen capture in Mac OS X, we use either Command + Shift 3 (Full screen), or Command + Shift 4 (User selection) The #2 is good but it wouldn’t allow us to select a specific window. To printscreen a specific window in Mac, try this. Command + Shift 4, then hit Space The mouse cursor will turn [...]

降旗 学の「長目飛耳」

by Takeshi AKIMA | about 17 hours ago | Read more

降旗 学の「長目飛耳」 2007年9月21日 サラリーマン、百の姓(かばね)となる NBonline(日経ビジネス オンライン):検索結果 もう1年前のものだけど、すげー面白い。剥製師とか、金髪のテーラーとか、フランチャイズレストランの覆面調査員とか。僕の世界は狭いって本当思

Ryan-orange-large http://sial.org/howto/debug/unix/parsepath

by Ryan L. Cross | about 18 hours ago | Read more

http://sial.org/howto/debug/unix/parsepath

My120_135 RE: Чудесная новость

by Ruslan Voloshin | about 18 hours ago | Read more

А почему в Russian ?

Innofisio.com ya está instalado

by Francisco de Juan | about 18 hours ago | Read more

El sitio web de Innofisio ya está instalado y listo!

Suerte!

Selenium Grid

by Raveendran | about 18 hours ago | Read more

Selenium Grid: Selenium Grid allows you to run Selenium tests in parallel, cutting down the time required for running acceptance tests to a fraction of the total time it currently takes. Run them all on a single machine (we’ve run up to 15 parallel processes on a laptop!) or on a server farm. Technical Mumbo Jumbo: Selenium Grid [...]

Highline - Ruby Gem

by Raveendran | about 19 hours ago | Read more

HighLine is about… Saving time. Command line interfaces are meant to be easy. So why shouldn’t building them be easy, too? HighLine provides a solid toolset to help you get the job done cleanly so you can focus on the real task at hand, your task. Clean and intuitive design. Want to get a taste for [...]

Rails.cache: Memcached, development mode and offline cache invalidation

by Jeff Dean | about 19 hours ago | Read more

Rails.cache rocks, but it can be tricky to set it up for development mode. For my purposes I need to:

  • Keep config.cache_classes to false so that I don’t have to restart my server while I develop
  • Cache all kinds of objects, not just strings
  • Be able to invalidate the cache easily from cron scripts or other offline processes
  • Test caching locally before deploying

The first thing I did was check out the excellent railscast and I read through the blog posts mentioned there. However, I couldn’t quite figure out how to get things to work – I kept getting strange errors where all of the methods were being stripped from my classes, rails was complaining that my classes didn’t exist or I was getting dreadful “singleton can’t be dumped” errors. After a lot of googling and experimentation, here is what finally worked for me:

Environment files

I like to develop quickly, test caching on my local and then deploy. To accomplish this I have 3 environments, setup like so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
  # config/environments/development.rb
  config.action_controller.perform_caching = false
  config.cache_classes = false
  config.cache_store = :mem_cache_store, '127.0.0.1:11211', {:namespace => "dev"}

  # config/environments/dev_with_caching.rb
  config.action_controller.perform_caching  = true
  config.cache_classes = true
  config.cache_store = :mem_cache_store, '127.0.0.1:11211', {:namespace => "dev_with_caching"}

  # config/environments/production.rb
  config.action_controller.perform_caching  = true
  config.cache_classes = true
  config.cache_store = :mem_cache_store, '127.0.0.1:11211', {:namespace => "production"}

Here are a few interesting points:

You don’t need to have memcached installed to develop locally

If you run your app locally without memcached installed, or without memcached running, you will see entries like this in your log

MemCacheError (No connection to server): No connection to server
Cache miss: Post.all ({:force=>false})

However, your app will work just fine. Rails will always execute the contents of the fetch blocks, and will return nil for any reads.

If memcached is running, you need to set cache_classes to true

To run memcached locally, you need to install memcached. I develop on a mac and manage packages with macports, so for me it was as easy as:

sudo port install memcached

Once memcached is installed, you can start it with

memcached -m 500 -l 127.0.0.1 -p 11211 -vv

which will print verbose logging to STDERR, or you can start it as a daemon like so:

memcached -m 500 -l 127.0.0.1 -p 11211 -d

Either of these will start a memcached process running on port 11211, and it will allocate 500MB RAM (most apps can get by with 128MB, or so I’ve heard).

Once this is running, though, you need to set config.cache_classes to true – otherwise you’re app will blow up.

Marshal.dump is finicky

Rails.cache calls Marshal.dump on any object you try to put in the cache. Marshal won’t work on everything though – and you may need to write your own serialization script. I’ve had problems with classes that have lots of module_eval statements that create methods dynamically and similar meta-programming techniques. If you start getting errors like “singleton can’t be dumped”, check to see if you have any meta-programming going on. I’ve also had issues with REXML objects.

If you do have an issue with a class that Rails won’t cache, you can easily bypass the built-in serialization by writing your own _dump and _load methods. See the ruby docs for more info.

Use a separate environment to test locally

I have a new environment named dev_with_caching that I use to test caching locally. I set up my database.yml file so that it points to the development database, but performs caching and in all other respects mirrors the production environment. To test locally with that environment, I use:

script/server -e dev_with_caching -p 3001

Clearing the cache

I mostly use Rails.cache to cache data – and mostly for arrays of objects – like Category.all. As such, it’s to keep all of this in the model, but cache invalidation can be trickly to manage. Here’s a pattern I’ve started to use a lot:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class Category < ActiveRecord::Base
  
  after_save      :reset_cache
  after_destroy :reset_cache
  
  def reset_cache
    self.class.reset_cache
  end

  class << self
    
    def reset_cache
      cached_all(true)
    end
    
    def cached_all(force = false)
      Rails.cache.fetch("Category.all", :force => force) do
        Category.find(:all, :conditions => {:active=>true}, :order=>'position')
      end
    end
  end
end

Here’s what’s happening:

The first time you call Category.cached_all it looks for the “Category.all” item in the cache. If it’s not there, it executes the contents of the block, and adds it to the cache. When you save or destroy a record the cache is invalidated.

If you want to force a refresh of the cache, just specify Category.cached_all(true) and it will be reloaded from the database. Once this is in place, it’s easy to write cache invalidation scripts that both clear the cache and reload it at the same time.

I’ve done this by adding a class method that reloads the data, which is triggered by after_save and after_destroy callbacks. I’m sure there are a number of plugins that will do all that and more, but for my purposes this simple pattern works for me most of the time.

Clearing the cache with cron

Finally, if you want to clear the cache at specified intervals you can do so easily with rake and cron. First, create a rake task that calls the model’s reset_cache method – since I normally have several classes with caching behavior I normally create a loop like so:

1
2
3
4
5
6
7
8
9
10
namespace :cache do
  namespace :reset do
    %w{Category Forum Post}.each do |klass|
      desc "Clear the #{klass} cache"
      task klass.underscore.gsub("/","_").pluralize => :environment do
        klass.constantize.reset_cache
      end
    end
  end
end

Now you can run

rake cache:reset:categories
and your Category.reset_cache method will be called. To make this work with cron, you’ll need a slightly different syntax. The following command is suitable to execute from a cron script, or manually from the command line:

RAILS_ENV=production rake -f /var/www/apps/yourapp/current/Rakefile cache:reset:categories

It might take a little while to grok Rails.cache – but once you do your apps will be faster and you’ll quickly become a wild caching fiend!

Cvoidds1 Fair Copyright - Calgary Chapter (Photo)

by Guy Davis | about 19 hours ago | Read more

The Bill C-61 protest at our MP's Stampede Breakfast drew out 40-50 people.

Cvoidds1 Kempton interviewed by CBC radio (Photo)

by Guy Davis | about 19 hours ago | Read more

We didn't draw much of a media presence. Just a single reporter from CBC Radio who looked bored to death. The group organizer Kempton tried his best to explain the issues, but most people don't understand or don't care. We'll see if they still feel that way when their kids start getting sued for hundreds of thousands of dollars and they have to sell their home to cover the damages.

Cvoidds1 The fuzz (Photo)

by Guy Davis | about 19 hours ago | Read more

Prentice travels with his own plain-clothes cops, but they called in uniformed officers when they saw us. Not sure why. It's not like a bunch of geeks are going to get too rowdy.

Cvoidds1 Bill C61 - Anti-competitive (Photo)

by Guy Davis | about 19 hours ago | Read more

One of the protesters with a nice big sign which speaks to the power the bill gives to a handful of large media distribution companies, with no real rights for either consumers or the hard-working musicians and content producers.

Networking Mac and Windows with VMWare

by Jeff Dean | about 19 hours ago | Read more

I recently discovered how easy it is to view my local development websites on multiple OS’s using VMWare. I use this primarily to see how awful my apps look in IE. Here’s how you can do it too:

Step1: Get Setup (the expensive part)

  1. Buy a mac
  2. Buy VMWare Fusion
  3. Buy Windows. Yes – if you want to run IE6 and IE7 you’ll have to buy two licenses. Yes, it will take you several hours of frustration and several hours on the phone with MicroSoft to get your licenses installed with VMWare.
  4. Download a few real OS’s and add them as virtual machines

Step 2: Find your network address

When you installed VMWare, it configured all of the necessary IP addresses for you. To find out what they are, open Terminal and type:

ifconfig

You’ll see something like:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
    inet 127.0.0.1 netmask 0xff000000 
    inet6 ::1 prefixlen 128 
    inet6 fdd3:5091:e6df:4c3d:21b:63ff:feab:d72e prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    ether 00:1b:63:ab:d7:2e 
    media: autoselect status: inactive
    supported media: autoselect 10baseT/UTP <half-duplex> 10baseT/UTP <full-duplex> 10baseT/UTP <full-duplex,hw-loopback> 10baseT/UTP <full-duplex,flow-control> 100baseTX <half-duplex> 100baseTX <full-duplex> 100baseTX <full-duplex,hw-loopback> 100baseTX <full-duplex,flow-control> 1000baseT <full-duplex> 1000baseT <full-duplex,hw-loopback> 1000baseT <full-duplex,flow-control> none
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    inet6 fe80::21c:b3ff:fe7c:916e%en1 prefixlen 64 scopeid 0x5 
    inet6 2002:4452:63ee::21c:b3ff:fe7c:916e prefixlen 64 autoconf 
    inet 10.0.1.199 netmask 0xffffff00 broadcast 10.0.1.255
    ether 00:1c:b3:7c:91:6e 
    media: autoselect status: active
    supported media: autoselect
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
    lladdr 00:1d:4f:ff:fe:73:a1:ba 
    media: autoselect <full-duplex> status: inactive
    supported media: autoselect <full-duplex>
vmnet8: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    inet 172.16.192.1 netmask 0xffffff00 broadcast 172.16.192.255
    ether 00:50:56:c0:00:08 
vmnet1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
    inet 172.16.43.1 netmask 0xffffff00 broadcast 172.16.43.255
    ether 00:50:56:c0:00:01 

Notice the last entry, vmnet1 – the inet address listed there is the address that all of your virtual machines can use to access your localhost. In my case, this is 172.16.43.1

Let’s say you have a local rails app running on http://localhost:3000/ – to access that app from anywhere (your mac or any or your virtual machines) just type http://172.16.43.1:3000/ in your browser.

Step 3

Just kidding ;->

References

Reborg Ruby Driven Development 4 JavaA screencast illustrating how to...

by Renzo Borgatti | about 19 hours ago | Read more



Ruby Driven Development 4 Java

A screencast illustrating how to install and use Buildr, Rspec and the Story Runner to test first a Java application. It’s long enough (1:15) to explain also some tricks and concepts behind BDD but the main goal is to explain how to move quickly from plain text requirements to working code from Ruby to Java. I’m planning to create a screencast for each user story and talk more about BDD and tracking. Have fun!

Tech Details:

  • Video recording: iShowU
  • Keystrokes:  KeyCastr
  • Post processing: none!
  • Format: 720p

lesson of the day: if you want merb to work, run the version from git.

by Mando Escamilla | about 20 hours ago | Read more

lesson of the day: if you want merb to work, run the version from git.

Karl Autonomous Mutant Festival 2008 unofficial webpage

by Rick Bradley | about 20 hours ago | Read more

Autonomous Mutant Festival 2008 unofficial webpage: seeing that barcamp nashville post reminded me of this ;-) (posted by ali)

Avatar-shady Windows Live Mail Bug: Can't Recognize Firefox 3x & Microsoft's Good Karma

by Srirangan | about 20 hours ago | Read more

I like Windows Live Mail (Web Edition not the desktop app) and I have been using it for a few months now in addition to my primary Gmail and personal IMAP mail account.

As I upgraded my default browser from Firefox 2x to Firefox 3x, I find that Windows Live doesn't recognize the browser correctly and throws up an error. This is a bug that should be easily rectifiable as Windows Live Mail worked perfectly with the Firefox 2 series.

To Microsoft's credit after wrongly diagnosing my Firefox 3 as an older browser they gave linked to "Upgrade My Browser" and the list included not only MSIE (of course) but also Firefox and Safari. Opera folks will not be too happy but it is a pleasant surprise to see Microsoft (which BTW gets more than its fair share of online "expert" critics) to link to its major competitors.

Here's a screenshot:

Links for 2008-07-04 [del.icio.us]

by Hui | about 20 hours ago | Read more

Links for 2008-07-04 [del.icio.us]

by Andreas Aderhold | about 20 hours ago | Read more

Links for 2008-07-04 [del.icio.us]

by Pedro Custódio | about 20 hours ago | Read more

Avatar Links for 2008-07-04 [del.icio.us]

by Duncan Robertson | about 20 hours ago | Read more

Links for 2008-07-04 [del.icio.us]

by Elliot Smith | about 20 hours ago | Read more

2477614714_700a70b2a0 Links for 2008-07-04 [del.icio.us]

by John Wulff | about 20 hours ago | Read more

Profile_large Koolhaas’ CCTV

by Ole Christian Enger | about 20 hours ago | Read more

Scheeren is the co-architect, with Rem Koolhaas, of the most eagerly awaited building in Beijing, the headquarters of the Chinese television network CCTV, a monumental construction that has become world-famous long in advance of its completion, scheduled for late this year. (The New Yorker: Forbidden Cities)

Metrain Any really interested readers?

by Yurii Rashkovskii | about 20 hours ago | Read more

I’ve decided to get rid of dedicated server where this blog runs. Being a bit lazy and having no clue about where do I want to host my blog I’ve decided you, readers, few questions:

  • Any suggestion for US-based VPS/dedicated-like uptime “shared”/grid/... hosting with zero overselling to keep this stuff running smoothly?
  • Is it really worth to bother with this blog at all? (i.e. did you find anything interesting here recently?)

Thanks!

Metrain Any really interested readers?

by Yurii Rashkovskii | about 20 hours ago | Read more

I’ve decided to get rid of dedicated server where this blog runs. Being a bit lazy and having no clue about where do I want to host my blog I’ve decided you, readers, few questions:

  • Any suggestion for US-based VPS/dedicated-like uptime “shared”/grid/... hosting with zero overselling to keep this stuff running smoothly?
  • Is it really worth to bother with this blog at all? (i.e. did you find anything interesting here recently?)

Thanks!

The New OS

by Rich Downie | about 20 hours ago | Read more

I started using Mac OS X late last year.  The thought of going back to any Windows platform makes me laugh.  The efficiency I’ve gained using Mac’s Leopard blows away any Microsoft product on any shelf.  However, the future in Operating Systems, I believe, lies in the Internet itself.  I find myself using Web mail [...]

Vou torcer pro grêmio bebendo vinho….

by Giovani Elisio | about 21 hours ago | Read more

  Conhecem o Wander?? aquele… o Wander Wildner?? Não ??? Ahh.. nós gremistas conhecemos e MUITO bem hehe da uma olhada na letra abaixo e depois assista o video da geral =p Bebendo vinho Eu vivo sozinho e apaixonado, Não tenho ninguém aqui do meu lado. Meu cachorro Vênus foi roubado, Fiquei um pouco preocupado. Vou me entorpecer bebendo vinho, Eu sigo só [...]

3439443_fd2c3ff2f6_m TimeMachineScheduler - set the backup interval of Time Machine [del.icio.us]

by Tony Buser | about 21 hours ago | Read more

IMG_0335.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0335.jpg

Alameda County Fair 2008

IMG_0333.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0333.jpg

Alameda County Fair 2008

IMG_0332.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0332.jpg

Alameda County Fair 2008

IMG_0331.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0331.jpg

Alameda County Fair 2008

IMG_0329.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0329.jpg

Alameda County Fair 2008

IMG_0328.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0328.jpg

Alameda County Fair 2008

IMG_0326.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0326.jpg

Alameda County Fair 2008

IMG_0325.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0325.jpg

Alameda County Fair 2008

IMG_0323.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0323.jpg

Alameda County Fair 2008

IMG_0321.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0321.jpg

Alameda County Fair 2008

IMG_0316.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0316.jpg

Alameda County Fair 2008

IMG_0312.jpg

by Henry Wagner | about 21 hours ago | Read more

hjw3001 posted a photo:

IMG_0312.jpg

Alameda County Fair 2008

IMG_0309.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0309.jpg

Alameda County Fair 2008

IMG_0307.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0307.jpg

Alameda County Fair 2008

IMG_0305.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0305.jpg

Alameda County Fair 2008

IMG_0302.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0302.jpg

Alameda County Fair 2008

IMG_0301.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0301.jpg

Alameda County Fair 2008

IMG_0300.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0300.jpg

Alameda County Fair 2008

IMG_0299.jpg

by Henry Wagner | about 22 hours ago | Read more

hjw3001 posted a photo:

IMG_0299.jpg

Alameda County Fair 2008

3439443_fd2c3ff2f6_m ZAGG | invisibleSHIELD | Apple iPhone 3G Cases, Screen Protectors, Covers, Shields, Skins, Invisible Shield [del.icio.us]

by Tony Buser | about 22 hours ago | Read more



Tell us what you think of the new BlogSphere feature. We are continually looking to improve and update the functionality based on your feedback.

Job Board

Job Boards
Find your next Ruby on Rails project or job.
Exclusive content, regularly updated - onsite and tele-working positions listed.

View the opportunities

Latest from the Weblog

Recent Recommendation

Marshall Sontag:

My go-to man for rails questions.

- Sbubble J.Z, United States