You may have some reason to break outside MVC model and I won’t give you lecture why you shoudn’t really do it, neither I won’t describe how you will burn in hell for commiting that kind of sin. Instead I will provide a working solution how it can be done. Just as a example of bad pratice :P.
So – how to render view inside model in Rails 3.2?
Monitoring your applications can be tricky, especially when you have to maintain more and more of them, that uses various technologies. So that’s why programmers helps other programmers with those tasks and nowadays you can choose from various monitoring services. I was mostly focused on airbrake, but overall it seems a little bit pricey for me. I mean it’s a great piece of software that fully supports Ruby on Rails and iOS and there are bunch of addons for PHP, .Net, Java, Python - you name it. But I needed something relatively simple that could allow me to monitor my apps build with RoR and PHP only, and I found shiny piece of code named errbit.
There is a time when you need to put some random data in your database. Maybe build up pretty frontend or manually test some features. I was using rake tasks that with a little help from Faker, at least until last few days - I needed to upgrade my tasks, but I mean - I had my test factories that were up-to-date, so I thought - why not use them? And so I did ;).
If you are using a git repository over https protocol you may encounter error:
server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none while accessing https://your-git-repo fatal: HTTP request failed
For some time I was struggling with efficient of ts_highligh function of postgres using Rails and pg_search. I had bunch of really long articles and I wanted to highlight search results in the content as well in the title with the power of tsquery and polish dictionary that we feed our database.
In the end solutions was quite simple really, maybe not the most elegant one but does the job just right and in the end your will end up still with ActiveRecord::Relation, so you can easily paginate your results with will_paginate or kaminari gem.
So, let’s break it down.
Quick and useful code snippet that you may want to use eg. while upgrading some old Rails projects. That HAML awesomeness you should use, Luke!
Last week I’ve got a brand new server to play with ;). The mission was clear (I’m going over there, I’m going to do the mission…) - upgrade, install all essential stuff, prepare and migrate the data from the old machine. So here’s what I’ve done so far (except setting up system accounts, ssh access and all that basic stuff).
Here’s small chunk of code that will help you out with testing paperclip. Basically it will stub any fie upload of any instance for given model. So now you won’t be left with ridiculous amount of files created after each test run. Yay!
Lately I have been adding new and new features to existing application and now came time when I have to play with some seriously old code. I mean - really old, forgotten and never refactored code. It’s just there, it’s working and nobody dares touching it. So before I started I need to prepare myself for the battle.
(Link to Part 1) Now let’s look at some tools that can help you migrating messy html into some more easy to maintain format. Obvious choice for many would be markdown, but as markdown is quite geeky I decided to go with well known by average user - and hated by many programmers - BBCode. BBCode would also allow me to implement some custom tags that I needed anyway - so from now we will stick with it.