{"id":927,"date":"2013-01-27T17:14:36","date_gmt":"2013-01-27T09:14:36","guid":{"rendered":"http:\/\/www.computersolutions.cn\/blog\/?p=927"},"modified":"2013-02-03T15:24:55","modified_gmt":"2013-02-03T07:24:55","slug":"ruby-ruby-ruby","status":"publish","type":"post","link":"https:\/\/www.computersolutions.cn\/blog\/2013\/01\/ruby-ruby-ruby\/","title":{"rendered":"Ruby ruby ruby&#8230;"},"content":{"rendered":"<p>As my friends in high places have been talking about Ruby for a long long time now, I thought I might take a look at installing a Ruby based app on one of our servers.  Sure, I could have hosted it on Heroku or similar (as I know people that know people), but I tend to do stuff in-house as China often decides to arbitrarily block useful 3rd party services at the drop of a hat.<\/p>\n<p>Looked fairly simple I thought.<\/p>\n<p>Bzzzt, wrong. (This is a bit of a diatribe, but hey, I have to whine somehow \ud83d\ude09 )<\/p>\n<p>Seems Ruby has a little bit to go in terms of friendliness.<\/p>\n<p>First up, was to follow the fairly simple instructions for installing the App I chose &#8211;  (Kandan).<\/p>\n<p>My first issue was this &#8211; <\/p>\n<p><code><br \/>\nInstalling eventmachine (0.12.10) with native extensions<br \/>\nGem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.<\/p>\n<p>\/usr\/bin\/ruby1.8 extconf.rb<br \/>\nextconf.rb:1:in `require': no such file to load -- mkmf (LoadError)<br \/>\n\tfrom extconf.rb:1<\/p>\n<p>Gem files will remain installed in \/var\/lib\/gems\/1.8\/gems\/eventmachine-0.12.10 for inspection.<br \/>\nResults logged to \/var\/lib\/gems\/1.8\/gems\/eventmachine-0.12.10\/ext\/gem_make.out<br \/>\nAn error occurred while installing eventmachine (0.12.10), and Bundler cannot continue.<br \/>\nMake sure that `gem install eventmachine -v '0.12.10'` succeeds before bundling.<\/code><\/p>\n<p>Hmm, mkmf, whats that?  <\/p>\n<p>No idea, lets take a quick look at apt-cache.<br \/>\nOk, so looks like we need ruby headers to compile.  <\/p>\n<p>A quick look google shows that at RubyForge shows that this has been an issue since oh, at least 2005.<\/p>\n<p><a href=\"http:\/\/rubyforge.org\/forum\/forum.php?thread_id=4161&#038;forum_id=4050\">http:\/\/rubyforge.org\/forum\/forum.php?thread_id=4161&#038;forum_id=4050<\/a><\/p>\n<p>Perhaps a nicer message might be &#8211; &#8220;Hey, I see you don&#8217;t have the ruby development headers installed, install some&#8221;, and maybe even download them.<\/p>\n<p>Even Perl is more user friendly than that when it comes to missing libraries, and Perl is famous for being obscure.<\/p>\n<p>Once I overcame that minor hurdle, the installer trundled away merrily, and failed on the next message<\/p>\n<p><code>Gem::InstallError: cloudfuji_paperclip requires Ruby version >= 1.9.2.<br \/>\nAn error occurred while installing cloudfuji_paperclip (3.0.3), and Bundler cannot continue.<br \/>\nMake sure that `gem install cloudfuji_paperclip -v '3.0.3'` succeeds before bundling.<\/code><\/p>\n<p>Debian has Ruby 1.91, and Ruby 1.8 in stable.<br \/>\n*and* the previous compiled gem (eventmachine) required 1.8 specifically.<br \/>\nI&#8217;m already smelling versionitis&#8230;  <\/p>\n<p>[more wizened geeks will say apologetic things like:<\/p>\n<p>#1 ah, but yes there is rb!<br \/>\n&#8211; Yes, but I&#8217;m coming at this from a fresh angle, and I don&#8217;t necessarily know about that.<\/p>\n<p>#2 This is quite debian specific!<br \/>\n&#8211; Yes, but it is a rather major distro..<br \/>\n]<\/p>\n<p>Lets see whats available from testing repo.<\/p>\n<p><code>apt-cache search -t testing ^ruby | grep 1.9<\/p>\n<p>...<br \/>\nruby1.9.1 - Interpreter of object-oriented scripting language Ruby<br \/>\nruby1.9.1-dev - Header files for compiling extension modules for the Ruby 1.9.1<br \/>\nruby1.9.1-examples - Examples for Ruby 1.9<br \/>\nruby1.9.1-full - Ruby 1.9.1 full installation<br \/>\nruby1.9.3 - Interpreter of object-oriented scripting language Ruby, version 1.9.3<br \/>\n<\/code><\/p>\n<p>Ok, so 1.9.3 should do it, lets install that.<\/p>\n<p><code><br \/>\napt-get install -t testing ruby1.9.3<br \/>\n<\/code><\/p>\n<p>Re-run the Bundle installer, and&#8230;<\/p>\n<p><code><br \/>\nInstalling cloudfuji_paperclip (3.0.3)<br \/>\nGem::InstallError: cloudfuji_paperclip requires Ruby version >= 1.9.2.<br \/>\nAn error occurred while installing cloudfuji_paperclip (3.0.3), and Bundler cannot continue.<br \/>\nMake sure that `gem install cloudfuji_paperclip -v '3.0.3'` succeeds before bundling.<br \/>\n<\/code><\/p>\n<p>Hmm&#8230;<br \/>\nLets double check.<\/p>\n<p><code><br \/>\n> ruby --version<br \/>\nruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]<br \/>\n<\/code><\/p>\n<p>Lets see. Ruby 1.9.3 >= 1.9.2 in my math book, so wtf.<\/p>\n<p>I can even install it fine manually, via &#8220;gem install cloudfuji_paperclip -v &#8216;3.0.3&#8217;&#8221; so its really full of poop.<\/p>\n<p>I decide to take a different tack &#8211;<br \/>\nLooking at the gems folder though, I don&#8217;t see the gem libraries for 1.9.3 there, so I guess Ruby is full of crap again, and lying about the error, although then why does building the gem manually NOT fail.  Sigh.<\/p>\n<p>I decided to take the rvm route<\/p>\n<p>https:\/\/rvm.io -> curl -L https:\/\/get.rvm.io | bash -s stable &#8211;ruby<\/p>\n<p>then<\/p>\n<p>source \/etc\/profile.d\/rvm.sh<\/p>\n<p>(still need to add to apache www-data group, but first lets get this compiled)<\/p>\n<p>rvm trundled away and installed 1.9.3 gems, so that *finally* cloudfuji_paperclip wasn&#8217;t bitching.<\/p>\n<p>&#8230;and we get to the next error.<\/p>\n<p><code>An error occurred while installing pg (0.12.2), and Bundler cannot continue.<br \/>\nMake sure that `gem install pg -v '0.12.2'` succeeds before bundling.<\/code><\/p>\n<p>I run that manually, and<\/p>\n<p><code>gem install pg -v '0.12.2'<br \/>\nBuilding native extensions.  This could take a while...<br \/>\nERROR:  Error installing pg:<br \/>\n\tERROR: Failed to build gem native extension.<\/p>\n<p>        \/usr\/local\/rvm\/rubies\/ruby-1.9.3-p374\/bin\/ruby extconf.rb<br \/>\nchecking for pg_config... no<br \/>\nNo pg_config... trying anyway. If building fails, please try again with<br \/>\n --with-pg-config=\/path\/to\/pg_config<br \/>\nchecking for libpq-fe.h... no<br \/>\nCan't find the 'libpq-fe.h header<\/code><\/p>\n<p>apt-get install  libpq-dev  solves that one.<\/p>\n<p>&#8230;and<\/p>\n<p>bombing on sqlite.<\/p>\n<p>apt-get install sqlite3<\/p>\n<p>retry<\/p>\n<p>Its at this point I start thinking about puppet and how that does dependencies in a graceful manner, but I digress.<\/p>\n<p>..and because I forget the development libraries, I need to also get those.<\/p>\n<p>apt-get install libsqlite3-dev <\/p>\n<p>Retry the bundle install, and *finally* getting a build.<\/p>\n<p>Oh joy.<\/p>\n<p>So, lets try run it.<\/p>\n<p>bundle exec rake db:create db:migrate kandan:bootstrap<\/p>\n<p><code>==  CreateAttachments: migrating ==============================================<br \/>\n-- create_table(:attachments)<br \/>\n   -> 0.0015s<br \/>\n==  CreateAttachments: migrated (0.0016s) =====================================<\/p>\n<p>==  AddSessionsTable: migrating ===============================================<br \/>\n-- create_table(:sessions)<br \/>\n   -> 0.0011s<br \/>\n-- add_index(:sessions, :session_id)<br \/>\n   -> 0.0004s<br \/>\n-- add_index(:sessions, :updated_at)<br \/>\n   -> 0.0004s<br \/>\n==  AddSessionsTable: migrated (0.0020s) ======================================<\/p>\n<p>==  DeviseCreateUsers: migrating ==============================================<br \/>\n-- create_table(:users)<br \/>\n   -> 0.0435s<br \/>\n-- add_index(:users, :email, {:unique=>true})<br \/>\n   -> 0.0005s<br \/>\n-- add_index(:users, :ido_id, {:unique=>true})<br \/>\n   -> 0.0005s<br \/>\n-- add_index(:users, :authentication_token, {:unique=>true})<br \/>\n   -> 0.0005s<br \/>\n==  DeviseCreateUsers: migrated (0.0452s) =====================================<\/p>\n<p>==  CreateChannels: migrating =================================================<br \/>\n-- create_table(:channels)<br \/>\n   -> 0.0011s<br \/>\n==  CreateChannels: migrated (0.0011s) ========================================<\/p>\n<p>==  CreateActivities: migrating ===============================================<br \/>\n-- create_table(:activities)<br \/>\n   -> 0.0012s<br \/>\n==  CreateActivities: migrated (0.0013s) ======================================<\/p>\n<p>==  AddGravatarHashToUsers: migrating =========================================<br \/>\n-- add_column(:users, :gravatar_hash, :text)<br \/>\n   -> 0.0007s<br \/>\n==  AddGravatarHashToUsers: migrated (0.0007s) ================================<\/p>\n<p>==  AddActiveToUsers: migrating ===============================================<br \/>\n-- add_column(:users, :active, :boolean, {:default=>true})<br \/>\n   -> 0.0007s<br \/>\n==  AddActiveToUsers: migrated (0.0007s) ======================================<\/p>\n<p>Creating default user...<br \/>\nCreating default channel...<br \/>\nrake aborted!<br \/>\nundefined method `to_i' for #<Channel:0x00000003f624c8><br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activemodel-3.2.11\/lib\/active_model\/attribute_methods.rb:407:in `method_missing'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activerecord-3.2.11\/lib\/active_record\/attribute_methods.rb:149:in `method_missing'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activerecord-3.2.11\/lib\/active_record\/connection_adapters\/column.rb:178:in `value_to_integer'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activerecord-3.2.11\/lib\/active_record\/connection_adapters\/column.rb:78:in `type_cast'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activerecord-3.2.11\/lib\/active_record\/attribute_methods\/dirty.rb:86:in `_field_changed?'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activerecord-3.2.11\/lib\/active_record\/attribute_methods\/dirty.rb:63:in `write_attribute'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/gems\/activerecord-3.2.11\/lib\/active_record\/attribute_methods\/write.rb:14:in `channel_id='<br \/>\n\/home\/cubieboard\/chat\/kandan\/lib\/tasks\/kandan.rake:35:in `block (3 levels) in <top (required)>'<br \/>\n\/home\/cubieboard\/chat\/kandan\/lib\/tasks\/kandan.rake:23:in `each'<br \/>\n\/home\/cubieboard\/chat\/kandan\/lib\/tasks\/kandan.rake:23:in `block (2 levels) in <top (required)>'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/bin\/ruby_noexec_wrapper:14:in `eval'<br \/>\n\/usr\/local\/rvm\/gems\/ruby-1.9.3-p374\/bin\/ruby_noexec_wrapper:14:in `<main>'<br \/>\nTasks: TOP => kandan:bootstrap<br \/>\n(See full trace by running task with --trace)<\/code><\/p>\n<p>Oh look, *what* a suprise.  Another error.<br \/>\nI&#8217;m starting to think  that nobody actually tests this stuff in real life.<\/p>\n<p>undefined method `to_i&#8217;<\/p>\n<p>A bit of googling, and it looks like Ruby has changed functionality, and broken things in 3.2.3<\/p>\n<p>See &#8211; http:\/\/stackoverflow.com\/questions\/13348980\/activerecord-to-i-method-removed-in-rails-3-2-9<\/p>\n<p>Plus, there are some security issues to in Rails (of course).<\/p>\n<p>*and* Kandan guys have cancelled it.<\/p>\n<p>However someone else has forked it, and is updating it.<\/p>\n<p>So, lets wipe all of that, and start again, shall we.<\/p>\n<p>-> https:\/\/github.com\/kandanapp\/kandan<\/p>\n<p>cd ..<br \/>\nrm -r kandan  &#8211;with-prejudice<br \/>\ngit clone  https:\/\/github.com\/kandanapp\/kandan<\/p>\n<p>edit the config\/database.yaml<\/p>\n<p>Add some sqlite3 (hey, the rest is, and at this point I just want something testable, I can tweak later).<\/p>\n<p>production:<br \/>\n  adapter: sqlite3<br \/>\n  host: localhost<br \/>\n  database: db\/production.sqlite3<br \/>\n  pool: 5<br \/>\n  timeout: 5000<\/p>\n<p>save.<\/p>\n<p>exec rake db:create db:migrate kandan:bootstrap<\/p>\n<p>Done.  Yay.<\/p>\n<p>Now to test.<\/p>\n<p>bundle exec thin start<br \/>\n>> Using rack adapter<br \/>\n>> Thin web server (v1.3.1 codename Triple Espresso)<br \/>\n>> Maximum connections set to 1024<br \/>\n>> Listening on 0.0.0.0:3000, CTRL+C to stop<\/p>\n<p>Ok, now *thats* finally working, I just need to setup a apache_proxy to that port on the actual url it will be sitting on, and finally it should work.<\/p>\n<p>*Famous last words*.<\/p>\n<p>Way more painful than it really needed to be.  Grr&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As my friends in high places have been talking about Ruby for a long long time now, I thought I might take a look at installing a Ruby based app on one of our servers. Sure, I could have hosted it on Heroku or similar (as I know people that know people), but I tend [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[25,4],"tags":[438,437],"class_list":["post-927","post","type-post","status-publish","format-standard","hentry","category-technical-mumbo-jumbo","category-useful-info","tag-kandan","tag-ruby"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/927","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/comments?post=927"}],"version-history":[{"count":6,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/927\/revisions"}],"predecessor-version":[{"id":930,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/posts\/927\/revisions\/930"}],"wp:attachment":[{"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/media?parent=927"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/categories?post=927"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.computersolutions.cn\/blog\/wp-json\/wp\/v2\/tags?post=927"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}