display_flash(:error) # to display a specific flash message
display_flash # to display all flash messages
1
2
3
4
5
6
7
8
9
10
11
12
13
| # Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
FLASH_TYPES = [:error, :warning, :success, :message]
def display_flash(type = nil)
html = ""
if type.nil?
FLASH_TYPES.each { |name| html << display_flash(name) }
else
return flash[type].blank? ? "" : "#{flash[type]}"
end
html
end
end |
Posted on 22-07-2008 | By: Amit
Category : Ruby on Rails
Tags: maths
1 x 8 + 1 = 9
12 x 8 + 2 = 98
123 x 8 + 3 = 987
1234 x 8 + 4 = 9876
12345 x 8 + 5 = 98765
123456 x 8 + 6 = 987654
1234567 x 8 + 7 = 9876543
12345678 x 8 + 8 = 98765432
123456789 x 8 + 9 = 987654321
1 x 9 + 2 = 11
12 x 9 + 3 = 111
123 x 9 + 4 = 1111
1234 x 9 + 5 = 11111
12345 x 9 + 6 = 111111
123456 x 9 + 7 = 1111111
1234567 x 9 + 8 = 11111111
12345678 x 9 + 9 = 111111111
123456789 x 9 +10= 1111111111
9 x 9 + 7 = 88
98 x 9 + 6 = 888
987 x 9 + 5 = 8888
9876 x 9 + 4 = 88888
98765 x 9 + 3 = 888888
987654 x 9 + 2 = 8888888
9876543 x 9 + 1 = 88888888
98765432 x 9 + 0 = 888888888
Posted on 14-07-2008 | By: Amit
Category : Ruby on Rails
Tags: globallogic, mod_rails, passenger, Rails
Mod_rails has come to rescue people form tedious rails application development. With mod_rails the work has become a lot easier, you do not have to worry about different things just few steps and your application is up and running, ofcourse there are options to modify the deployment to your needs.
There are few prerequisites for mod_rails to work, first you need Apache and secondly you need Ruby and Rubygems.
Step 1: We need to update rubygems
sudo gem update
Step 2: We need to install mod_rails(passenger)
sudo gem install passenger
Step 3: Now we need to install Apache2 headers
sudo aptitude install apache2-prefork-dev
Step 4: Now we need to install Apache2 module
sudo passenger-install-apache2-module
There will be a screen which takes you further. If there are any dependencies that are needed then it will be asked for on this screen.
After successful installation there is just one thing left, we need to copy some lines to the Apache2 main config file , open the file “apache2.conf” in a text editor and then paste these lines at the end of the file:
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-1.0.4/ext/apache2/mod_passenger.so
RailsSpawnServer /usr/lib/ruby/gems/1.8/gems/passenger-1.0.4/bin/passenger-spawn-server
RailsRuby /usr/bin/ruby1.8
Restart Apache
sudo service apache2 restart
Done!!
Posted on 23-06-2008 | By: Amit
Category : Ruby on Rails
Requires Ruby 1.8.7 or higher.
1
2
3
4
5
6
| keys = [1,2,[3,4]]
[1, 2, [3, 4]]
values = ['a','b',['c','d']]
["a", "b", ["c", "d"]]
Hash[ * keys.zip(values).flatten(1) ]
{1=>"a", [3, 4] => ["c", "d"], 2 => "b"} |
Posted on 16-06-2008 | By: Amit
Category : Ruby on Rails
Handy little helpers to check if a file was provided to a controller, and to save it.
1
2
3
4
5
6
7
8
9
10
11
| def file_provided?
[StringIO, Tempfile].include?(@file.class) and @file.size.nonzero?
end
def save_file
if @file.is_a? Tempfile
FileUtils.cp(@file.path, path)
elsif @file.is_a? StringIO
File.open(path, "wb") { |disk_file| disk_file << @file.read }
end
end |