Friday, January 20, 2012
Sunday, October 16, 2011
Mysql2::Error (Invalid date: xx) on a text field?!
I have this rule, the longer it takes to figure out a bug, the dumber the solution is going to be. This one was no exception.This bug on the rails adapter for mysql (the native Mysql2 for Windows) cost me a day and a half of bewilderment.
The symptoms were that when populating a particular field in a table caused the created_at filed that was directly after to corrupt.
Although the entry would save successfully, once i tried to retrieve it, it would omit an argument error, without any explanations or indication to the field that was causing the problem.
After literally hours spent reinstalling and reconfiguring and redeploying my application and the run times involves i stumbled upon this error "Mysql2::Error (Invalid date: xx)" where xx was the text value of the field preceding the "created_at" standard field.
A quick search on Google pointed me to the bug in Mysql2.
My solution was (cross my heart and hope to die) was to add an extra field that i never populate before the date fields.
Good Luck.
The symptoms were that when populating a particular field in a table caused the created_at filed that was directly after to corrupt.
Although the entry would save successfully, once i tried to retrieve it, it would omit an argument error, without any explanations or indication to the field that was causing the problem.
After literally hours spent reinstalling and reconfiguring and redeploying my application and the run times involves i stumbled upon this error "Mysql2::Error (Invalid date: xx)" where xx was the text value of the field preceding the "created_at" standard field.
A quick search on Google pointed me to the bug in Mysql2.
My solution was (cross my heart and hope to die) was to add an extra field that i never populate before the date fields.
Good Luck.
Wednesday, August 24, 2011
Switching between Ruby Runtime versions on Windows
A nice tool for switching between ruby versions on windows is the pik gem
To use it, run gem install pik
Install locally by running: pik_install C:\pik
And add the installation dir (in this case c:\pik) to your system path.
Once you have that set up, you add ruby installations by running pik add C:\Ruby192\bin
and switch between them by pik 192
Running Rails 3.x with mysql2 on Windows
Every time I have to set up Ruby & Rails with MySQL on windows its the same old drag.
The easy part goes like this:
Installing Ruby 1.9: download ruby installer
Installing gem: follow gem installation instructions
Install MYSQL: I like using the WAMP server, but its also possible to go for the MySQL regular installation
and:
Install Rails 3.x: run gem install rails
But then you will need to:
Install mysql2 by running gem install mysql2 -v 0.2.6
and
Copy libmySQL.dll from mysql bin to ruby-home/bin
Now generate and run your server.
Don't forget to configure your database.yml file
Note: that if when sunning the server, it responds like:
Could not find gem 'mysql2 (~> 0.2.11)' in any of the gem sources listed in your Gemfile
Then go into your server root directory and open up the Gemfile
substitute the line:
gem 'mysql2', '~> 0.2.11'
with
gem 'mysql2', '~> 0.2.6'
...And your good to go.
The easy part goes like this:
Installing Ruby 1.9: download ruby installer
Installing gem: follow gem installation instructions
Install MYSQL: I like using the WAMP server, but its also possible to go for the MySQL regular installation
and:
Install Rails 3.x: run gem install rails
But then you will need to:
Install mysql2 by running gem install mysql2 -v 0.2.6
and
Copy libmySQL.dll from mysql bin to ruby-home/bin
Now generate and run your server.
Don't forget to configure your database.yml file
Note: that if when sunning the server, it responds like:
Could not find gem 'mysql2 (~> 0.2.11)' in any of the gem sources listed in your Gemfile
Then go into your server root directory and open up the Gemfile
substitute the line:
gem 'mysql2', '~> 0.2.11'
with
gem 'mysql2', '~> 0.2.6'
...And your good to go.
Thursday, August 11, 2011
Ruby 1.8.7 CSV parser workaround
Apparently there is some kind of problem when using the CSV parser for particular text structures. I want able to determine the exact cause of this problem expect that for some csv structures, the parse process result in an error.
In my frustration I resorted to write my one parser that is implemented as following:
def self.parse(text)
rows=text.split("\r")
res=[]
rows.each{|row|
res << row.split(",")
}
res
end
And amazingly enough, that's what did the trick.
Independent on Sundays.
In my frustration I resorted to write my one parser that is implemented as following:
def self.parse(text)
rows=text.split("\r")
res=[]
rows.each{|row|
res << row.split(",")
}
res
end
And amazingly enough, that's what did the trick.
Independent on Sundays.
Tuesday, August 2, 2011
Flex and Rails
Hi Peter
Thanks for visiting my blog
In my company we have quite an extensive use of the ruby - flex combination, and to my experience it has the best results for the fastest development time.
The key to communicate between rails and flex is to set up REST services that generate json/xml structures.
On the server side, all you have to do is have the controller render the result as json/xml using the following line:
render :json => {an object with the data you want to send}
or
render :xml => {an object with the data you want to send}
It works just as well in rails 3 as in 2.x
On the flex side, it gets a little more complicated, but in essence, you send an http request to the rails service and on the ResultEvent you encode the string you get to json/xml respectively
here is a code example:
protected function call(action:String,arg:Object,resFunc:Function, failFunc:Function,resultFromat:String="e4x"):void{
var service:HTTPService;
service = new HTTPService();
service.url = server+"/"+action;
service.method = "POST";
service.contentType = "application/xml";
service.resultFormat = resultFromat;
service.useProxy = false;
service.addEventListener(ResultEvent.RESULT,resFunc);
service.addEventListener(FaultEvent.FAULT, failFunc);
arg["account_id"] = accountId;
arg["service_key"] = serviceKey;
var req:Object = new Object();
req["data"] = arg
service.send(req);
}
public function getDetails(result:Function,fault:Function):void{
var o:Object = new Object();
call("get_details",o,result,fault);
}
private function detailsResult(e:ResultEvent):void{
details= JSON.decode(String(e.result));
}
Subscribe to:
Posts (Atom)