Posted by Kasper Tidemann on Thursday 3rd of February 2011 02:02:13 AM
We’re doing the final testing of our brand new IMAP module for Meeho!™. In short, it’ll give you complete integration of your e-mail inbox, sent mails etc. with contacts, clients, and projects in Meeho!™. We honestly can’t wait to release version 2.2 on the new server platform, packed with new features — it’s gonna be sweet.
Posted by Kasper Tidemann on Monday 22nd of November 2010 09:00:04 PM
I was just looking for this, because I forgot the command and issuing gem help doesn’t say a word about it — at least I couldn’t find it. To do a so-called selfupdate of your gem (RubyGems) installation, run the following command:
sudo gem update –system
(Those are two dashes and not just one, in cause your browser displays them as one.)
There you go.
Posted by Kasper Tidemann on Monday 11th of October 2010 11:25:19 PM
Here is the situation: you’ve got your own Ruby on Rails application, and you need to create an API that spits out XML for use somewhere. This is what you could be doing:
respond_to do |format|
format.xml { render :xml => @users.to_xml
end
The above will create and return fully functional XML which is all good and dandy.
Well, it’s not. The above will mirror each and every detail about your users table in your database. But what if you don’t want to include the user passwords in the XML? What if you want to rename one of the fields to something else in your XML?
You use the Builder. With the help of the Builder, you can modify the XML to look like anything you want and not just mirror your table structure completely. Here is how you use the Builder:
xml = Builder::XmlMarkup.new
xml.instruct!
xml.users do
@users.each { |user|
xml.username user.username
xml.email user.email_address
xml.write-whatever-you-want-here user.whichever-field-you-need
}
end
respond_to do |format|
format.xml { render :xml => xml.target! }
end
The above code creates a new Builder object, then defines for a set of users to be shown in the XML. Then, the @users array is processed, and inside each user node in the XML you’re pretty much able to do whatever you want – including calling other methods you might need on-the-fly.
So whenever you need just a tad bit more freedom when working with XML, discard the .to_xml approach and create your own Builder object. That works like a charm!
Posted by Kasper Tidemann on Monday 22nd of March 2010 10:51:59 PM
With file uploads in Ruby on Rails, e.g. an upload of a 2 KB CSV file, you’ll often run into trouble trying to decipher the encoding of the Tempfile string data stored in params[:my_upload_form][:uploaded_file] or whatever you’ve named your input field.
If you want to keep everything to one encoding, you could make use of Iconv.conv(‘UTF-8′, <whatever encoding>, string) to convert the data from the input field to UTF-8. But to make the iconv() wrapper work properly, it needs to know what to convert from… So how do you acquire this knowledge?
Try to use the Ruby gem rchardet by Jeff Hodges. Here is an example of how to use it:
require ‘rchardet’
[...]
cd = CharDet.detect(params[:my_upload_form][:uploaded_file])
encoding = cd['encoding']
converted_string = Iconv.conv(‘UTF-8′, encoding, params[:my_upload_form][:uploaded_file])
The above is not bullet proof, but it’ll get you going. If you have alternative ideas in this regard, please comment to let us all know.