Posts

Better Git Log in browser window

Better Git Log For all the Git users try this command , it will generate a better logging for git. It also shows your recent commits and the code difference in your browser window. You can also mention a port number using -p option. git instaweb --httpd webrick Enjoy !! Play with it :)

Rails Error Messages on Fields and other Customizations

Rails Error Messages on Fields and other Customizations If you wanted to show an error message with the field and also you wanted to highlight that particular field. Here you have to create a new file inside  config/initializers folder of your application, make sure to restart your application if you are making any sort of changes inside the config folder. Here we are basically adding a class "error" to the field and showing a span with the error message. rails-fields-with-errors.rb ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| class_attr_index = html_tag.index 'class="' errors = Array(instance.error_message).join(',') if !class_attr_index.nil? html_tag.insert class_attr_index+7, 'error ' else html_tag.insert html_tag.index('>'), ' class="error"' end %(#{html_tag}  #{errors} ).html_safe end ...

How to use arguments with before filter with other options

How to use arguments with before filter with other options Lets suppose you have a method in the application controller "find_instance" that you wanted to use as before filter with an added argument "category" .So use the below mentioned code. before_filter { |c| c.find_instance 'category' } If you waned to add more options to your before filter do something like this. before_filter(:except=>[:index,:new,:create]) { |c| c.find_instance 'category' } And then in the application controller you do something like this def find_instance(obj) instance = obj.camelize.constantize.find(params[:id]) instance_variable_set("@#{obj}",instance)  end It will give you @category as an instance variable which will become @category = Category.find(params[:id])

Generate Scaffold for already Existing files

Generate Scaffold for already Existing files. First you can check all the exiting options available to you by using a following command. rails generate -h if you'd like to generate a controller scaffold for your model, you can use scaffold_controller you can also use --skip option to skip any files which exist.

Procs , Lambda and their difference

Procs  Like variables hold data, procs hold the code itself. example_proc = Proc.new{ puts “I am a Example” } We will use proc by using .call method example_proc.call lambda { foo } and proc { foo } is essensially the same thing, you can use both interchangeable in your code. There are couple of differences which are as follows One of the main difference and major difference between them is that  Proc object does not care at all for the number of arguments you pass to it e.g. p = proc{|a,b| p "The value of a is #{a.inspect}. The value of b is #{b.inspect}"}   p.call 1,2 # => "The value of a is 1. The value of b is 2"   p.call 1 # => "The value of a is 1. The value of b is nil"   p.call 1,[2,3],Class.new # => "The value of a is 1. The value of b is [2,3]"   So , it takes the first two arguments and discards the rest but if we pass  less than two it will assume that the other(s) are nil l = lambda{|a,b| p "Th...

PostgreSql : Most common issues

Installation To install PostgreSQL, run the following command in the command prompt: sudo apt-get install postgresql Test the installation by following command here 8.3 is the version which i am using sudo /etc/init.d/postgresql-8.3 restart Now that we can connect to our PostgreSQL server, Please make sure that you restart the server after making the below mentioned changes, the next step is to set a password for the postgres user. Run the following command at a terminal prompt to connect to the default PostgreSQL template database: sudo -u postgres psql template1 The above command connects to PostgreSQL database template1 as user postgres. Once you connect to the PostgreSQL server, you will be at a SQL prompt. You can run the following SQL command at the psql prompt to configure the password for the user postgres. ALTER USER postgres with encrypted password 'your_password'; Now you can also use the PGADMIN for the GUI with the following mentioned username and password.

Multiple Skype Instance on MAC (Snow Leopard)

Run the following command to open another instance of skype sudo /Applications/Skype.app/Contents/MacOS/Skype