Rails migration check exist table and column

Rails migration check exist table and column

In Rails migration we can check column or table is exist or not
If column or table exist then we can skip migration otherwise run migration

Check column_exists?

We can checks to see if a column exists in a given table.
column_exists?(table_name, column_name, type = nil, options = {})

example:
column_exists?(:suppliers, :name, :string)

http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/column_exists%3F

Check table_exists?

We can checks to see if the table table_name exists on the database.

table_exists?(table_name)

Example:
table_exists?(:developers)

http://apidock.com/rails/ActiveRecord/ConnectionAdapters/SchemaStatements/table_exists%3F

Better errors in rails

better_errors is a Rack middleware that replaces the default standard rails error page with a more useful one.

The default Rails error page is also useful, but there is so much output that we don’t usually need and also there is a lot of other things we might need to see.

The features of better_errors gem are awesome:
1) Full stack trace
2) Source code inspection for all stack frames (with highlighting)
3) Local and instance variable inspection
4) Live REPL (Read-Eval-Print Loop) on every stack frame

In this local and instance variable inspection is so useful.

We can immediately see the instance variables that are set at the time of the error.

Installation:

You can install it as:

group :development do
  gem "better\_errors"
end

Add this lines to your Gemfile:

bundle install

If you would like to use Better Errors’ advanced features (REPL, local/instance variable inspection, pretty stack frame names), you need to add the bindingofcaller gem by @banisterfiend to your Gemfile:

and then bundle install

This is an optional dependency however, and Better Errors will work without it.

For more details click here better_errors gem
bindingofcaller gem

Git commtit message format with git commit template

I want to use git commit template in my default git commit message.

There are following steps:

Update ~/.gitconfig  file by command

gedit ~/.gitconfig

set commit template file as:

[commit]
template = ~/.gitmessage

Then update the ~/.gitmessage by command:

gedit ~/.gitmessage
Feature/Bug: # we can mention Issue/Bug/Ticket number

Changes: # What we have done.

Todo: # Any Dependency like rake db:migrate or bundle install

Now we need to

git add

and

git commit

to edit commit messgae

Gem indian_postal_codes: Fetch Indian city, district and state by Indian postal codes

Gem indian_postal_codes is the best gem for fetching Indian city, district and state name by Indian postal codes using Yaml database.
Its very easy to use in our rails application.

We can use this gem as:

run:

gem install indian_postal_codes

or inlude this line in gem file

gem 'indian_postal_codes'

then run:

bundle install

Example:

Suppose, I want to fetch details of Indian Postal code 562110

IndianPostalCodes.details('562110')
# => {:city=>"Devanhalli", :district=>"Channapatna", :state=>"Karnataka"}

For more details: indian_postal_codes https://github.com/DevilalDheer/indian_postal_codes

Learning technologies

I am software developer working on ruby on rails. I am developing eCommerce, chat application, static and dynamic website, mobile application, Hybrid App.

Most of the project by companies and some by self learning new technologies. I am good learner and team player.

My Skills: Ruby on Rails, C, Java, HTML, CSS, JQuery, Coffee-script, Mobile Application, Hybrid App, Titanium, Cordova, Phonegap, Node.js, Angular.js, Ionic Framework, Heroku, Git, PostgreSql, MySql, MongoDb, MVC framework, SQLite, Redis, HybridApp

Now days I am good fan of Toptal.com, this site is good for learning techonlogies.

Breadcrumb on edit page in Active Admin

Rails ActiveAdmin: Incorrect breadcrumb

I have found an issue in the breadcrumb on the EDIT page
like this

Admin / Products / # /

I have resolved this issue as:

We can try to define display_name method in our ‘Product’ model.


class Product < ActiveRecord::Base
  def display_name
    "#{ field_name }"
  end
end

or

We can try to define to_s method in our ‘Product’ model.

class Product < ActiveRecord::Base
  def to_s
    field_name.to_s
  end
end

Installing android studio on Linux 64 bit system needs Linux 32 Bit Libraries

During installing android studio on Linux 64 bit system

I have faced this issue:

/android-studio/bin$ ./studio.sh
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=350m; support was removed in 8.0
[ 14438] WARN - dea.updater.SdkComponentSource - Couldn't find existing SDK
[ 595217] ERROR - ard.ConsolidatedProgressStep$1 - Unable to run mksdcard SDK tool.
com.android.tools.idea.welcome.install.WizardException: Unable to run mksdcard SDK tool.

To fix this issue, we need to install 32-bit compatibility libraries on our system.
$ sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1

For older versions of Ubuntu the command to run:
$ sudo apt-get install ia32-libs

Reference: http://tools.android.com/tech-docs/linux-32-bit-libraries