Just for the record, my new blog/website is http://andreapavoni.com. I’ve also moved some technical posts there.
ruby & rails developer, freelance, *nix lover, teacher
When it comes to develop a CMS, one of the main problems concerns where or how to store and organize views (templates, partials, layouts) for particular needs like different layouts for specific pages, (sub)domains or multi-languages. The ideal way is to store views on a database, indeed there are some CMSs that solve this problem with similar approaches, like Radiant and Locomotive.
However, I wanted something that let me to reuse this feature on several projects (because a custom CMS may have different features), and to store only certain views, according to specific content and needs.
So, I’ve developed Panoramic, a simple gem inspired from some ideas found in José Valim’s excellent book Crafting Rails Applications. Simply put, once Panoramic is installed, you can store your views on database. It works through an implemetation of ActionView::Resolver class: Rails will lookup views as if they were on filesystem. In controller, you’ll tell where and when to use those views, using prepend_view_path and append_view_path on a controller or action basis (they are both implemented as class and instance methods). Depending from the method you’ll use, Rails will respectively look for views on database, then it will fallback on filesystem, or viceversa. Quite easy, right?
I’ll not show any code here, because there’s a full explanation on Panoramic’s README. As a final note, at the moment it works only with ActiveRecord, but I’ve planned to extend support to DataMapper and Mongoid as soon as possible. It’s very easy to implement, the main problem is about testing: maybe I’ll write some rspec’s custom matchers to reuse with different ORMs, like carrierwave.
Il nuovo video di Hackitaly. Stay Tuned per il prossimo evento
Con tutto il rispetto al buon Saviano che ci ha fatto piangere e sognare con i suoi libri e le sue trasmissioni televisive , noi di Hackitaly pensiamo che l’Italia debba ricominciare da persone come ANTONIO TRAPANI , hacker e developer di Hackitaly .
E da tutti gli startupper e developers italiani .
ANTONIO, grazie di esistere, e grazie per quello che stai facendo per l’Italia, probabilmente la copertina di Wired non avrai mai pensato di averla.
Ma noi te l’abbiamo data e secondo noi questa è la più bella di tutte.
La comunità italiana di Ruby è attiva come non mai!
In occasione del primo Codemotion ci ritroveremo tutti…
yeah, it was funny!
126 commits later and after 2091 files changed, Coderloop infrastructure is eventually running on Rails 3. The full story of this migration deserves a blog post on its own and we will describe some opensource code that we have released. We are very proud of this big achievement and happy about…
In the last post, I explained how to make conditional searches based on conditional params. I wrote a very simple search model that returns a real model with query done by Arel. I refactored the code to make i simpler to use:
The constructor takes the model you want to search in, and an hash of params to use, they’ll be the request params when used from controller. Note that if some param value is an empty string, it will be ignored: this lets the visitor to leave blank some fields in the search form and make it conditional.
To save typings, when specifying conditions, you can omit the value, because it’s taken from the params hash. By the way, if you need some more control, you can specify another value. Finally, you can pass a block to make it easier to read. Here’s a real usage example from a controller:
When Search#result is called a model instance is returned, it can still be ordered.
According to Arel README, there’s no support for OR conditions yet, I hope it will be included soon.
What do you think about?