ninajansen.dk

ninajansen.dk header image 1

Entries Tagged as 'Ruby on Rails'

Fragment cache expiry from background jobs is a hot mess

juni 11th, 2008 · Comments

In order to get a cache sweeper to actually do anything when it is triggered, it must be called from a controller, and that controller must be instantiated though a http request.
This is what I have learned from trying to expire fragment cache from background scripts in Ruby om Rails. It simply is not possible. [...]

[Read more →]

Tags: Ruby on Rails · cache · rant · sweepers

Testing caching with memcache, cache_fu and rspec

maj 21st, 2008 · Comments

I use cache_fu for caching my rails application. I use a “fat models, skinny controllers strategy”. This means that my Author model has code like this:

def cached_books
get_cache(:author_books) do
Book.find_by_author_id(self.id)
end
end

This method caches all books belonging to an author. Cache fu does not cache belongs_to or has_(one|many) relationships, and that’s why we have this method. But this also [...]

[Read more →]

Tags: Ruby on Rails · cache · memcache · rspec

Cache sweepers in Rails, put them in app/models!

maj 14th, 2008 · Comments

So i’ve been spending hours tracking this one down: I wanted to have cache sweepers in rails and followed the advice from railscasts and railsevny. Those tutorials tell you to put sweepers in an app/sweepers directory and add that directory to your load path. DON’T DO THAT. That simply did not work for me (using [...]

[Read more →]

Tags: Ruby on Rails · cache · sweepers · tips

In place editing in rails

maj 13th, 2008 · Comments

So basically, the official plugin is old and cant really deal with restful routing. For some reason, when I used the url_for method in my views, the in place editor javascript function couldn’t interpret the (restful) route properly and sent a post request to ‘/controller/1/edit’ to an action named “1″ with an id set to [...]

[Read more →]

Tags: REST · Ruby on Rails · tips

Rails tips #1

maj 2nd, 2008 · Comments

These might be completely obvious to everyone, but I found them useful:

If you want to migrate a specific database, you can do it by setting RAILS_ENV on the command line. Like this:
rake db:migrate RAILS_ENV=production
If you want to see all the rake tasks in your application with a description of what they do, execute:
rake [...]

[Read more →]

Tags: Ruby on Rails · tips