About ruby on rails, hackintosh, iphone3g and etc.

Tuesday, December 15, 2009

Install Nokogiri on Leopard

If you have this problem:

HI. You're using libxml2 version 2.6.16 which is over 4 years old and has
plenty of bugs. We suggest that for maximum HTML/XML parsing pleasure, you
upgrade your version of libxml2 and re-install nokogiri. If you like using
libxml2 version 2.6.16, but don't like this warning, please define the constant
I_KNOW_I_AM_USING_AN_OLD_AND_BUGGY_VERSION_OF_LIBXML2 before requring nokogiri.

Here is the solution:

Install the latest libxml2 and libxslt

Make a source directory somewhere and do the following commands to grab the latest versions of libxml2 and libxslt:

$ curl -O ftp://xmlsoft.org/libxml2/libxml2-2.7.3.tar.gz

$ curl -O ftp://xmlsoft.org/libxml2/libxslt-1.1.24.tar.gz

Once done, unpack both like so:

$ tar xzf libxml2-2.7.3.tar.gz

$ tar xzf libxslt-1.1.24.tar.gz

Now change into the libxml directory and build it:

$ ./configure

$ make

$ sudo make install

Now jump back to the libxslt directory and do the same:

$ cd ../libxslt-1.1.24

$ ./configure

$ make

$ sudo make install

If you want, go ahead and delete the sources to save space. Now you’re ready for the final step.

Install Nokogiri

Now installing Nokogiri is super easy once we tell it where to link.

$ sudo gem install nokogiri -- --with-xml2-include=/usr/local/include/libxml2 --with-xml2-lib=/usr/local/lib


Saturday, December 5, 2009

CORE_RL_magick_.dll not found

For Windows Environment Only

This error happens when during installation of ImageMagick, the path is not set, you can set the path manually at my computer, environment.

set PATH: C:\Program Files\ImageMagick-6.5.6-Q8

Upon this, if you still encounter error like R6034, it means the dll has some problem, need to install MS VC++ 2008 Redistributable.


Using RMagick to add text to image

Here is the way to do it:

require 'rubygems'
require 'RMagick'
include
Magick

image
= Image.new(50, 50) {
self.background_color = "white"
}
text
= Draw.new
text
.annotate(image, 0,0,0,40, 'Named Colors') {
self.fill = 'black'
self.pointsize = 32
}
image
.write("image.png")

If you encounter error in mongrel like

Mongrel not starting: `initialize_without_backlog': Cannot assign requested address, it may be because if you use rmagick and the process keeps running as it cannot find the requested font. Then you need to find the process like ruby script/server. look for the process id.

use this command in OSX: ps -ef

look for the line ruby script/server
get the pid (e.g. 925652)
then use this command

kill -9 925652

Installing RMagick in Snow Leopard

This entry is extracted from this blog:http://blog.d27n.com/2009/08/26/mac-os-x-snow-leopard-rails-mysql-and-sphinx/

Today I also got my SnowLeopard copy and updated my 10.5 System to 10.6. Yeah well, as you, I had some problems with the RoR installation but after about 4 hours I finally got it.

In your blog, you asked for some tips about the RMagick installation. First of all, the mentioned script installs some outdated versions, that’s why I used another way. First of all, I installed the current version of MacPorts (for SnowLeopard).

http://distfiles.macports.org/MacPorts/MacPorts-1.8.0-10.6-SnowLeopard.dmg

Then I tried just to install ImageMagick, that failed for me, because of libxml2 compiled for the i386 architecture. So you have to recompile / update it first.

sudo port install libxml2
sudo port install ImageMagick

It was enough for to have a running x64 version of ImageMagick on SL. It could be, that some other libs are compiled in i386, too. Than you have to update it first before compiling ImageMagick.

My next step was the installation of the RMagick gem. It’s maybe a bug, but after my first run of

sudo gem install rmagick

I get the error, that rmagick was configured for a wrong version if ImageMagick, after the second run of the gem install rmagick, I hat a working solution.

Thursday, December 3, 2009

Enable Multiple Buttons in a Form in Rails

Sometimes we need more than one button in the form. To do so in Ruby On Rails, we have to do the following:

Create a method in the controller to accept the form input
e.g

def approve_form
case params[:submit]
when "Approve"
redirect_to :action=>"approve"
return
when "Reject"
redirect_to :action=>"reject"
return
end
end


in your form, do this

Wednesday, December 2, 2009

link_to popup error in IE

If you encounter problems that the popup does not appear in link_to function in IE browser, below will solve your problem.

Make sure there is no space between the names of the window

e.g.

link_to "View This Image", :action=>:show_image, :popup=>['window_name', 'height=300,width=300']

window_name should not have spaces.