I’m an Ubuntu user and wanted to give the Feedzirra gem a shot and play with some RSS feeds today but unfortunately I ran into a few problems — which were CAKE to fix thanks to apt-get and hopefully this post will save you some time!Continue reading
Author: me
Install Gems from GitHub
I’ve seen a few people confused by this, and I was stumped back in the day SO:
FYI, if you want to install gems from GitHub you need to add it as a source!
How? Easy!
sudo gem sources -a http://gems.github.com
Now you can install any gem hosted on GitHub with something like:
sudo gem install yo-mama
One other thing to note. Gem names when installing from GitHub are formatted as: username-projectname
So if you were looking @ user “billybob” and he forked a gem/project called “fishface”… the way you install would be:
sudo gem install billybob-fishface
RailsCollab
If you are using RailsCollab on Ubuntu and emails are not working, check the config and make sure the path to sendmail is /usr/sbin/sendmail . This tripped me up because the default path to sendmail is /usr/bin/sendmail and i hardly noticed it was wrong!
Postfix in Ubuntu = /usr/sbin/sendmail
libxslt Problems When Installing the Mechanize Gem
Ran into an interesting problem today that took me a bit to figure out. I need to automate some web tasks so of course I turned to Mechanize. When trying to install the gem on Ubuntu I ran into the following problem:
io@crazo:~$ sudo gem install mechanize Building native extensions. This could take a while... ERROR: Error installing mechanize: ERROR: Failed to build gem native extension. /usr/bin/ruby1.8 extconf.rb install mechanize checking for xmlParseDoc() in -lxml2... yes checking for xsltParseStylesheetDoc() in -lxslt... no checking for exsltFuncRegister() in -lexslt... no checking for libxml/xmlversion.h in /opt/local/include,/opt/local/include/libxml2,/usr/include/libxml2,/usr/include,/usr/include/libxml2,/usr/local/include/libxml2... yes checking for libxslt/xslt.h in /opt/local/include,/opt/local/include/libxml2,/usr/include/libxml2,/usr/include,/usr/include/libxml2,/usr/local/include/libxml2... no need libxslt *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/bin/ruby1.8 --with-xml2lib --without-xml2lib --with-xsltlib --without-xsltlib --with-exsltlib --without-exsltlib Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/nokogiri-1.1.0 for inspection. Results logged to /usr/lib/ruby/gems/1.8/gems/nokogiri-1.1.0/ext/nokogiri/gem_make.out
This line threw a hint:
checking for libxslt/xslt.h in /opt/local/include,/opt/local/include/libxml2,/usr/include/libxml2,/usr/include,/usr/include/libxml2,/usr/local/include/libxml2… no
Anyways, after some Googling i found this post on Industry Zero and resolved the issue with a simple package installation:
io@crazo:~$ sudo apt-get install libxslt1-dev
After that, noooo problem installing mechanize and even resolved an issue i was having with nokogiri getting installed!
io@crazo:~$ sudo gem install mechanize Building native extensions. This could take a while... Successfully installed nokogiri-1.1.0 Successfully installed mechanize-0.9.0 2 gems installed Installing ri documentation for nokogiri-1.1.0... Installing ri documentation for mechanize-0.9.0... Installing RDoc documentation for nokogiri-1.1.0... Installing RDoc documentation for mechanize-0.9.0...
.profile Tip
If you are doing development on Linux using a bash shell this is a nice alias a time saver might be to setup some aliases. I am using an alias to start script/server via simply typing ‘ss’.
Here’s all you have to do:
Jump into your home directory and open hidden file .profile:
user@kenyacoffee:~/railz/bort$ cd user@kenyacoffee:~$ user@kenyacoffee:~$ nano .profile
Add the following line:
alias ss="./script/server"
Exit nano and write out the changes to .profile.
In your home directory execute the source command:
user@kenyacoffee:~/railz$ cd user@kenyacoffee:~$ source .profile
Now change back to your rails project directory and try running ‘ss’:
user@kenyacoffee:~$ cd railz/bort user@kenyacoffee:~/railz/bort$ ss => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails 2.2.0 application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment...
Feels good to type less!
Shorthand Using a Ternary Operator
This is great for writing short and poignant if-statements in Ruby and IMO makes code a bit more readable.
The syntax of the ternary operator:
[condition] ? [true expression] : [false expression]
Example Usage:
[sourcecode language=’ruby’]irb(main):182:0> animal = “Dog”
=> “Dog”
irb(main):183:0> animal == “Dog” ? “You are a Dog” : “WHAT ARE YOU?!?”
=> “You are a Dog”[/sourcecode]
Batch Importing and Watermarking with Attachment_fu
In this exercise I had Posts with many image attachments attached with attachment_fu and rmagick. I also had a bunch of old data that i wanted to import in using a rake task and finally all image attachments needed to be watermarked.
First my assumptions:
- “A Post can have many Image attachments”
- You have the attachment_fu plugin installed already
Here is how it’s done.
What is here?
Hello All,
This blog is designed to function as a sort of journal where i can document code snippets and stuff like that. If you have anything to say, don’t hold back!