Open Source

Simple Rails helper for using OnClick on div, tr and other tags


I came across the issue of making set of div tags’ onClick event to be connected with a remote function, yet I couldn’t find a helper method to that and I made a simple and stupid helper method by cannibalizing link_to_remote and link_to_function helper methods.

usage: just like using link_to_remote, yet we don’t specify “name”, since there’s no text going inside the tag except the onclick event info

//e.g:
<<%= onclick_to_remote :url => my_restful_url %>; class="my_1">;

I works for me and get the work done.. arguments such as :with are supported.. Posting it here hoping someone will find it useful or may be improve it as well.
check out the pastie for better viewing pleasure and understanding http://pastie.caboo.se/200546

def onclick_to_remote(options = {})
*args = remote_function(options)
function = args[0] || ''
function = update_page(&amp;block) if block_given?
"onclick=\"#{function}; return false;\""
end

Posted in AJAX, Featured, Ruby / RailsComments (8)

Ajax Banner Rotator (uses JQuery) & Mootools conflict diffused (hopefully :)


There was an issue reported by Revive Coffeehouse about mootools conflicting with the Ajax Banner Rotator.

Revive Coffeehouse said… Hey, Just as a heads up.. when using this module, it seems to disable the mootools menu effects, reverting them to standard CSS driven menus. So, I have a fancy banner rotator, but no fancy menus : ) Any idea if this can be fixed??

Possibly this is due to conflict of Mootools and JQuery. http://forum.mootools.net/viewtopic.php?pid=26204 hopefully it’s been fixed on newer JQuery release (which I’ve used here). Please keep me posted on that issue.

I never expected to keep this thing up to date and fixing bugs (I’m no coder by profession as well as I’ve turned my evil eye towards RubyOnRails these days). But seems the rule that parents responsible of taking care of children applies here as well :)

V0.3b and 0.4b has also fixed the IE issue where the whole page becoming a link

Anonymous said… i love how this module works unfortunately its not working properly with my site its making the whole page a link

Download Module and read release notes http://joomlacode.org/gf/project/ajax_banner/



Posted in AJAX, JoomlaComments (5)

Ajax Banner Rotator Updated - Now Supports Joomla 1.5 Natively


Just updated the Ajax Banner Rotator for Joomla 1.5 and now supports 1.5 without the legacy mode. Randomizing banners are still disabled since IE giving some error that I cant understand.. something to do with randomizing on jqrotator.js file. Comments welcome..

Thanks for the patience. I forgot to update the plug-in, even though I marked it supports 1.5 ;)

Download Module and read release notes http://joomlacode.org/gf/project/ajax_banner/


Read other posts on update, first release

Posted in AJAX, JoomlaComments (1)

attachment_fu file rename file rename / change filename : HOWTO


I’ve been looking for a solution to change the filenames of the uploaded files and came across the great tutorial at http://the.railsi.st/2007/8/21/how-to-customize-attachment_fu-file-names/ but it was not what i was exactly looking for. I had issues with viewing the saved files because the thumbnail property does not exist for the new attachment etc.

I’m posting what I did and it changes the filenames to what ever we specify.. Works for me, and hopefully it will work for someone else as well.. :)

checkout the pastie for a better view of the code http://pastie.caboo.se/161062

class Photo < ActiveRecord::Base
	#Options for has_attachment
	has_attachment	:content_type	=> :image,
			:storage 	=> :file_system,
			:size => 1.kilobyte .. 10.megabytes,
			:resize_to => '500>',
			:thumbnails => { :thumb => '125' },
			:path_prefix => 'public/images/product_pics',
			:processor    => 'MiniMagick'
	validates_as_attachment

	belongs_to  :product

	#Filename changing stuff, these methods resides in attachement_fu plugin files..
	#and we are just modifying them to fit our needs and putting them in our model
	#so other models will not be effected
	def full_filename(thumbnail = nil)
		file_system_path = (thumbnail ? thumbnail_class : self).attachment_options[:path_prefix]
		@thumb = self.thumbnail unless (@thumb = thumbnail) #checks if thumbnails info already exist
		File.join(RAILS_ROOT, file_system_path, self.product.code, thumbnail_name_for(@thumb, self.product.code))
	end

	#Change the filenames and thumbnail suffixes
	def thumbnail_name_for(thumbnail = nil, asset = nil)
		suffix = "_#{thumbnail}" unless thumbnail.blank?  #sets suffix by the name of the thumbnail set in has_attachment options
		extension = filename.scan(/\.\w+$/) # extracts extension
		return "#{asset}#{suffix}#{extension}" # change the filename to fit your needs
	end

	before_thumbnail_saved do |record, thumbnail|
		thumbnail.product_id = record.product_id
	end

end

Posted in Ruby / RailsComments (0)

Controller Inheritance and RESTful routes


Sometimes we might need to implement controller inheritance; to have a DRYer code, a logical way to organize our project using or let it be purely the personal preference. It would be especially helpful for an admin area of a website (which I wanted to implement as well as shown in the example of Justin French)

Admin Lounge Controller:

class Admin::ProductsController

This has been well explained here and it helped me to fix few things which I’ve been struggling to do and also convinced me i was doing something meaningful.

then if we need to use restful routing for these and if you dont know how to create the route similar to admin_products_url or edit_admin_product_url. routes.rb got an example how to get it done. However you can find a better example here.

Controller Inheritance
http://justinfrench.com/index.php?id=122

RESTful routes for Controller Inheritance
http://railstips.org/2007/4/28/namespaces-added-to-routes

Great RESTful RAILS tutorial
http://www.b-simple.de/download/restful_rails_en.pdf

Posted in Ruby / RailsComments (0)

RAILS on Ubuntu 7.1


Windows platform may not be the ideal place to develop or deploy your Apache/MySQL/PHP or RoR(Ruby on Rails) applications. However I came across few problems myself trying to setup Ruby on Rails Development Machina on Linux (Ubuntu 7.10). Once you fix them, it works like a charm

There are many installation instructions and fixes posted everywhere. I thought of putting my own version to consolidate installation instructions and fixes to possible problems. I’ve also listed the sources I’ve referred myself and its recommended visit those websites if you need more detailed instructions as well as up-to-date news.

POSSIBLE ISSUES

  • rubygems (LoadError) require’: no such file to load – rubygems (LoadError)
  • MySql socket error No such file or directory - /tmp/mysql.sock
  • Open ssl problem when starting Webrick server

1. Install libopenssl-ruby1.8 » fixes the Webrick server error on startup

2. Install libmysqlclient15-dev » fixes the MySQL sock not found issue
Reference:
https://help.ubuntu.com/community/RubyOnRails

3. Install Ruby and Gems
Even though you can easily get ruby installed using apt-get it doesn’t fix the issue. We’ll have to compile it ourselves.
Reference:
http://www.thirdbit.net/articles/2007/10/04/installing-ruby-186-on-ubuntu-feisty-fawn-704/
http://www.urbanpuddle.com/articles/2007/08/17/mongrel-cluster-1-0-2-and-ruby-1-8-5
http://www.urbanpuddle.com/articles/2008/01/09/install-ruby-on-rails-on-ubutu-gutsy-gibbon-apache-version

  1. Download ruby
  2. tar xjvf ruby-1.8.6.tar.bz2
  3. cd ruby-1.8.6
  4. sudo apt-get build-dep ruby1.8
  5. ./configure –prefix=/usr
  6. make
  7. sudo make install
  8. ruby -v and if you see something like ruby 1.8.6 (2007-03-13 patchlevel 0) [i686-linux] ruby is installed :)
  9. then we install ruby gems. download rubygems and extract it.
  10. cd rubygems-1.0.1
  11. sudo ruby setup.rb

4. Install Rails
Reference:
http://rubyonrails.com/down
http://rubyonrails.com/

sudo gem install rails –include-dependencies

We are done.. Worked for me, and fingers crossed it’ll work for anyone as well :)

Posted in Linux, Ruby / RailsComments (2)

AJAX Banner Rotator 0.2b


Update 0.2b

  • Text from “Banner Custom text” field can be displayed with the rotating images and the text can be formatted using an external style sheet using the ID “rot_txt” (eg: ul#ajaxb_rotator #rot_txt {margin:10px 10px 10px 10px;})
  • Links can be turned off if necessary
  • The module can be used as an image rotator (with advanced functionality) by using the banners as source images (create a client and then it can be used to manage images)

Module is available for downloading from http://joomlacode.org/gf/project/ajax_banner/ and its hosted in www.joomlacode.org

Posted in AJAX, JoomlaComments (0)

AJAX Banner Rotator


Release Notes:
v0.2b released - 30-June-2007
Joomla 1.5 Native Support - 27-Mar-2008
JQuery / Mootools Conflict fixed -  28-Mar-2008

AJAX Banner Rotator works with Joomla! v1.x (on J! v1.5 not been tested yet). it is a combination of “AJAX header rotator” module and “All Banners” module. it simply combines the functionality of both modules. Read the full story

Posted in AJAX, JoomlaComments (56)