Posts tagged ‘Rubyonrails’
DB2 Rocks
qs = Question.find_by_sql
"select X.* from ots_schema.questions," +
"XMLTABLE (\'$d/question\' passing document as \"d\" " +
"COLUMNS question_text VARCHAR(200)" +
"PATH \'question_text\') as X"
qs.first.question_text.lstrip => "Which of the following is the correct syntax to set the DB2COMM variable to TCPIP?\n "
If DB2 was had a good DB2 driver and a ActivePureXML (or something adapter) it would so f*ckin rock. Just look at the sample. And the dynamic nature of ruby would enable the flexibility of xml documents.
Please IBM please. DB2 for mac and decent support on Ruby. Don’t make me write things like this no more:
# Once again fixing IBM_DB bugs the ugly way # with_scope anyone? add_index :'ots_schema.users', :login
or
t.column :document, :xml
Google reinvents the wheel
About porting Ruby on Rails to Javascript:
In an effort to increase developer productivity at Google, Steve tried to convince the company to adopt Rails (and consequently Ruby) as a programming language. When that fell on deaf ears (Google really does not want to increase the number of languages that must be supported by their infrastructure), Steve decided to do what any other frustrated programmer would do: he ported Rails to JavaScript. Line by line. In 6 months. Working 2000 hours. Steve is a coding stud.
From: Steve Yegge ported Rails to JavaScript
In this six months Steve could have contributed to the rails core and improved the framework to a great extent. If he found security issues like the article refers than he should have fixed them in rails. I cannot even begin to understand why he didn’t by the way. Or at least reported them.
My conclusion of seeing that google allowed a employee to waste 6 months of work because they don’t want to increase the number of languages that must be supported by their infrastructure is that Google is Dumb.
Steve seems like a smart guy so if I was told to rewrite Ruby on Rails by an employer I cannot understand why he didn’t – at the very least – refused to do so and pointed out how stupid it was to reinvent the wheel. I simply hate javascript and love ruby. I think javascript is the worst thing there is in the internet. That’s one of the reasons I decided to take a chance on XForms. Well but that’s a personal opinion and has nothing to do with the case!
The question is:
So will this bring something new to the web?
Yes! But it’s not that this wheel is great and the other was flat. It can bring something but just because Google has the power to do that, in any language they decide to use. They have the man power to go beyond what rails offer.
But does this make the decision less dumb?
No. They could do it in rails and improve a great open source product.
Or is it that hard for engineers at google to learn a new language??
has_one :through
Finally we will be able to refactor our ugly code when we have this situation (changeset 9067):
class User < ActiveRecord::Base has_many :channels end
class Channel < ActiveRecord::Base belongs_to :network belongs_to :user end
class Group < ActiveRecord::Base
has_many :channels
has_one :network,
:through => :channels,
:conditions => ['channels.alive? = ?', true]
end
Another good news is that the RubyForge place for the OTS project was finally approved. So guess I will be doing some work on it this afternoon.
Valid and Well-formed XML Documents in Ruby on Rails
If your working with DB2 on Rails you probably need to check if the xml document is – at least – well formed.
I found a neat plugin called validates-xml that uses REXML to see if documents are well formed.
To install it simply
svn co http://validates-xml.googlecode.com/svn/trunk/ validates-xml-read-only
And copy that folder to vendor/plugins.
You can easily integrate schema validation with a validates_xml_with_schema method. But you should use REXML as it cames with the standard ruby bundle since version 1.8.
To use it simply restart your server and
validates_xml :xmldocument
That’s it!
Working different models in the same form on Ruby on Rails

Well it’s been a heck of a week, loving somethings on rails and hating others :P
Anyway I had a problem with working with different models on a form. If you are having the same kind of issues I’ll give you some pointers:
- Railscasts (ep.73, 74, 75)
- The problem I had and the solution I found (newbie code inside :P)
- Implementings has_many relationships on RailsForum
- Rails: Presenter Pattern (thanks to André Medeiros)
- Chunky Bacon!
My notes file is so big I think I’ll never solve all those issues. *g* Anyway another pointer I can give you is to check out haml. I didn’t used it but it sure is simpler than html.
Random in Ruby on Rails
So your doing a find on your model and you want a random instance. I didn’t find a method to do this so I decided to make my own.
In this case I wanted a random quote. So after generating the model all I had to do was:
def self.random Quote.find_by_id rand(Quote.count) + 1 end
And now you can simply call your random quotes in any controller action you desire. Just
@rquote = Quote.random
If this is the lamest ruby ever please feel free to give me some feedback :) I will be delighted to learn a different way!
Life on the rails
I found Ruby in a talk with one of my friends. We were talking about how a problem that can be solved in Haskell in one line of code, could take hundreds to do so in Java or C#. It was obvious that, for some specific problems, Haskell was simpler and adequate.
Want a sample? Code permutation with n levels in C.
perms xs 0 = [[]]
perms xs n = [ p : ps | p <- xs, ps <- perms xs (n - 1)]
And like this he introduced me to Ruby on Rails. I was very thrilled to see a language that is dynamic, object oriented and adequate for web developing. I immediately thought about learning it, I just love learning new languages.
Today I checking my feeds and found a post about seven reasons to switch back to PHP (from Ruby).
It seems Ruby is like Haskell: the code looks greats and promises a lot, but it still doesn’t get where imperative languages do. (I’m still going to learn it, I just can’t resist it)
For now I’m waiting for a language that joins all that is good from imperative, functional, logic and object oriented paradigms.
If you know such programming language leave it as a comment.
|
PHP $61,000 |
|
|
Ajax $76,000 |
|
|
Ruby $70,000 |
|
|
Java $77,000 |
|
|
C# $78,000 |
|
|
Haskell $52,000 |
