Friday, November 30, 2007
RESTful authentication plus simple_captcha (Captcha image did not match with text)
Posted by
Sonal
at
4:47 PM
0
comments
Links to this post
Labels: restful_authentication, Ruby on Rails, simple_captcha delegate libraries
Monday, November 26, 2007
Step by step RMagick installation for Windows
- The RMagick README asks you to update your Rubygems version to at least 0.9.4. The latest available version at this time is 0.9.5. But people have reported problems with RMagick installation using 0.9.5 version of RubyGems.
- I faced the same problem when I tried to install RMagick after updating my RubyGems version to 0.9.5. So I decided to install RubyGems 0.9.4 to be on the safe side and try insalling RMagick again. This was the status of installation of RMagick using RubyGems 0.9.5 "Successfully installed rmagick-1.15.9-unknown 1 gem installed."
- Download rubygems-0.9.4.zip from RubyForge Ruby Gems. I downloaded it to C:\Softwares.
- Unzip rubygems-0.9.4.zip.
- cd to C:\Softwares\rubygems-0.9.4\rubygems-0.9.4. You should be able to see a file named setup.rb in this folder. On command prompt cd to this directory and key in: ruby setup.rb
- This installs 0.9.4 version of RubyGems.
- To double check the correct version of Ruby Gems key in (from any directory): gem --version and that should print 0.9.4
- We need to use the rmagick-win32 gem for installing RMagick on Windows. This gem is bundled with a a copy of the ImageMagick Windows installer so we don't need to download our own copy.
- Download the rmagick-win32 gem from the RMagick project page on RubyForge and unzip it into a temporary directory.
- I downloaded RMagick-1.15.9_IM-6.3.5-8-Q8_prod.zip from RubyForge RMagick and saved it in C:\Softwares on my desktop.
- Unzipped RMagick-1.15.9_IM-6.3.5-8-Q8_prod.zip
- Unzipped RMagick-1.15.9.tar.zip that was inside RMagick-1.15.9_IM-6.3.5-8-Q8_prod
- Clicked on ImageMagick-6.3.5-8-Q8-windows-dll to install ImageMagick. This installs ImageMagick but I am not sure if we are supposed to install this manually or whether gem install rmagick will do it for us. Nonetheless, since I am a chicken, I installed it myself. This installer does not seem to interfere with an existing, different version of ImageMagick.
- To see the version of ImageMagick installed, key in: convert --version
- Now install the rmagick gem. C:\Softwares\RMagick-1.15.9_IM-6.3.5-8-Q8_prod> gem install rmagick-1.15.9-win32.gem --local This prints 'Successfully installed rmagick, version 1.15.9'.
- I did not need to uninstall Ruby and install it through the one click installer. (What are you talking about?)
- Now restart your development server. ruby script/server
- There is no need to 'require RMagick' in your environment.rb or source code.
- Errors after installation of RMagick, on restarting the development server.
"warning: already initialized constant OPTIONS > ... ruby/gems/1.8/gems/rails-1.2.3/lib/commands/servers/mongrel.rb:18:> undefined method `options' for []:Array (NoMethodError)" This seems to be because of an error in RMagick installation. Key in: gem list on the command prompt to see if rmagick-win32 is indeed showing in the list. If not, you need to install RMagick. - "Procedure entry point HSL transform could not be located in the dynamic link library CORE_RL_magick.dll" OR "CORE_RL_magick.dll not found". For CORE_RL_magick.dll problems you can do 2 things:
check if ImageMagick is correctly installed. If there are any other installations of ImageMagick installed, it might be better to uninstall them.Restart your Windows machine. Yes, not the development server, but your computer. This makes available all the paths to ImageMagick. This tip, courtesy: http://www.texxors.com/?p=24. To make sure if this is indeed the problem, key in: convert --version on a path not in ImageMagick\bin folder (where convert.exe) resides. If it complains of invalid drive etc. you know that the path to ImageMagick is not being recognized. Restarting the machine helps correct this problem. After restarting, if you key in: convert --version, you should be able to see: Version: ImageMagick 6.3.5 09/01/07 Q8 http://www.imagemagick.orgcopyright/: Copyright (C) 1999-2007 ImageMagick Studio LLC
Posted by
Sonal
at
2:39 PM
2
comments
Links to this post
Labels: CORE_RL_magick.dll, ImageMagick, RMagick for Windows, RMagick installation, Ruby on Rails
Monday, November 19, 2007
Step by step subversion (svn), Ferret and acts_as_ferret installation on Windows
Subversion installation
- Go to Subversion project page. This page lists the subversion packages for various platforms. Scroll down to the Windows area.
- Select the Apache server version. I select 'Win32 packages built against Apache 2.2'. If you are not sure or do not find your version of Apache listed, selecting Apache 2.2 may still do.
- This will take you to the list of downloads. Scroll right to the end and savesvn-win32-1.4.5.zip. This is Subversion 1.4.5 Win32 binaries for Apache 2.2.x. You can select whichever version suits your needs. This is the one I selected.
- On your PC, unzip this folder. This will create a folder structure like so (if you unzip it in C:\Softwares): C:\Softwares\svn-win32-1.4.5\svn-win32-1.4.5
- Append the path of the Subversion bin directory (where svn, subversion, svnlook etc. reside), C:\Softwares\svn-win32-1.4.5\svn-win32-1.4.5\bin to your Control Panel -> System -> Advanced System Settings -> Advanced -> Environement Variables -> System Variables -> PATH.
- Now open a brand new command prompt and type svn. If it does not throw an unknown program error, hurray! You've installed Subversion successfully.
- For downloading the latest stable version of Ferret gem go to Ruby Forge Ferret page. From here, select ferret-0.11.5-mswin32.gem or whichever win32 version shows topmost.
- Suppose you downloaded the gem file to your C:\Softwares directory. You can install ferret by keying in gem install ferret.
C:\Softwares>gem install ferret
Successfully installed ferret, version 0.11.5
Installing ri documentation for ferret-0.11.5-mswin32...
Installing RDoc documentation for ferret-0.11.5-mswin32...
C:\Softwares - That's it. You're done
- To install it in your Rails application say, test_app, change directory to your app. Then key in the following on the command prompt to install the latest stable version of acts_as_ferret.C:\InstantRails\rails_apps\test_app> ruby script/plugin install svn://projects.jkraemer.net/acts_as_ferret/tags/stable/acts_as_ferret
- If this command ends up throwing error or just returns without any status information, check the URL and check whether svn is indeed included in your PATH.
- If everything goes OK, this installation will spit out lots of information about the installation as it goes.
- RESTART the development web server (mongrel/webrick) to be able to use acts_as_ferret in your application.
- Congrats! You can now go ahead and use acts_as_ferret in your application. If the view code gives the error 'Unknown class acts_as_ferret in class ...', you probably forgot to restart the development web server.
- Acts_as_ferret Wiki
- Using the acts_as_ferret DRb server (Here is the answer to: what the $@#* is a DRb server?)
- A splendid acts_as_ferret tutorial
Posted by
Sonal
at
11:04 AM
0
comments
Links to this post
Labels: acts_as_ferret installation, Ruby on Rails, subversion installation, svn for windows
Thursday, November 15, 2007
RESTful routing for a singleton resource (singular RESTful routes)
The generated RESTful routes are by default pluralized. So we get routes like /topics/12/posts/4. But what about the routes for resources that are singleton? A user can have a single identity object describing his first name, last name, location etc. We'd like to be able to refer to identities in singular within the context of the logged in user. It would be idiomatically better if the route were /identity/new. In this case map.resource comes to the rescue.
1. On the command line, key in:
ruby script/generate scaffold_resource Identity
2. In config/routes.rb key in:
# map.resources :identities <= comment out automatically added mapping map.resource :identity, :controller => "identities"
3. In the views code, change URLs from identity_path(@identity) etc. to identity_path. E.g. in new.rhtml change the form :url to identity_path from identity_path(@identity)
4. In the controller, which is still called IdentitiesController, "index" action can be removed now since we're only supposed to have one such resource per user. Since we are not passing params[:id] anymore, we need a way to get hold of the Identity object that corresponds to the currently logged in user. This can be done using something like:
@identity = @logged_in_user.identity
assuming @logged_in_user is the currently logged in user and 'has_one' Identity. The idea is to have a means to get the identity object.
5. That's it. You can access URLs such as
http://localhost:3000/identity/new and http://localhost:3000/identity;edit
instead of
http://locahost:3000/identities/new and http://localhost:3000/identities/12;edit
More information on singleton resources can be found in the Rails API documentation. Looking closely at the URLs described in the controllers for map.resource and map.resources in the API documentation clarifies point#3 about removing @identity, that is, params[:id].
Posted by
Sonal
at
10:42 PM
0
comments
Links to this post
Labels: Ruby on Rails, singleton resource, singular RESTful routes
RESTful Rails: Anorexic Controllers and Fat Models
Nonetheless, here are some resources for those aiming for a RESTful lifestyle. (better sleep, less worries and more cash)
Posted by
Sonal
at
9:30 AM
0
comments
Links to this post
Labels: REST resources, RESTful, Ruby on Rails
