Sunday, 26 August 2012

Active admin relationships between models

I have used active admin for my rails application admin section.

I have 2 tables products and category.

Product class

belongs_to :category


Category class

has_many :products



I have created two resources for the above two models in admin folder. Every thing went well and for both the resources its displaying the list view perfectly.

When I try to create the product from product new screen its displaying the categories options as list of all categories objects and not the categories records.

I have made some goggling and came to find solution that we need add the below method in my category class to display the category names in the drop down to choose while creating the product.


In my category class

  def to_s
    category_name
  end


Thank You,
Uma Mahesh.

generating active admin controller

Hi,

Active admin provides a good admin interface. Inorder to generate a controller in active admin you need to run the below command

> rails g active_admin:resource User

The actual notation that should be used for active for a model is 'resource'. By running the above command you will create a resource for user class.

We need to refer the active admin classes as resource for model class.

Thank You,
Uma Mahesh.

Wednesday, 22 August 2012

Engine Yard Has Steped forward by adding Node.js support

Hi,


Enine Yard is one of the top most PAAS providers in the Cloud environment. Presently Ruby On Rails and PHP are playing around at Engine Yrad. Now Engine has added Node.js to its Support and This will help startups to build application fastly.

With the addition of Node.js to the Engine Yard Cloud supported frameworks, developers can deploy highly scalable and concurrent systems.

You can start deploying Node.js application into Engine yard and let share your views.

Thank You,
Uma Mahesh.

Custamize active admin find_by request instead of ID

Hi,

I have a requirement, where I need to find the record with find_by_name in active admin. But by default active admin finds the records with id. After googling I came to see this can be done by using before_filter as below

ActiveAdmin.register Product do
    before_filter :only => [:show, :edit, :update, :destroy] do
        @product = Product.find_by_name(params[:id])
      end
end

Thank You,
Uma Mahesh.

Agent admitted failure to sign using the key. Permission denied (publickey).

Hi,

solution : ssh-add ~/.ssh/id_rsa


I have faced the below error while cloning the code from github. I have added my keys to heroku and every thing went good. But I am facing the below error

Agent admitted failure to sign using the key. Permission denied (publickey).

Cloning into master...
Agent admitted failure to sign using the key.
Permission denied (publickey).
fatal: The remote end hung up unexpectedly


Finally after google I found the solution as below

> ssh-add ~/.ssh/id_rsa

I have ran the above command and works for me.


Thank You,
Uma Mahesh.

Thursday, 16 August 2012

PG ERROR While creating GIN Index

Hi,

I am getting below error while creating GIN Index in rails through migration

rake aborted!
An error has occurred, this and all later migrations cancelled:

PG::Error: ERROR:  data type text has no default operator class for access method "gin"
HINT:  You must specify an operator class for the index or define a default operator class for the data type.
: CREATE INDEX discussions_gin_question ON discussions USING GIN(question)

Tasks: TOP => db:migrate
(See full trace by running task with --trace)


After goggling I came to see its due to not making that column as to_tsvector

I have changed my migration to execute as below

CREATE INDEX products_gin_question ON products USING GIN(to_tsvector('english', question))


Thank You,
Uma Mahesh.

Creating GIN Index for database columns in rails Migration.


Hi,

Indexing the database columns plays an important role in database query optimisation. Indexing also increases the application performance.

While working with full text search, I recommend to use the GIN Index. It will speed-up the full-text search.


GIN (Generalised Inverted Index)-based index. While creating Column as GIN Index we need to make that column as tsvector type.

Here is the full stack view of GIN Index : http://www.postgresql.org/docs/8.3/static/textsearch-indexes.html


Coming rails migration we can create GIN Index by simple commands as below

Create migration file:

> rails g migration add_ginindex_products

class AddGinindexProductions < ActiveRecord::Migration
  def up
    execute "CREATE INDEX products_gin_question ON products USING GIN(to_tsvector('english', question))"
  end

  def down
    execute "DROP INDEX products_gin_question"
  end
end


> rake db:migrate

The above migration will create the GIN Index for the products table.

Thank You,
Uma Mahesh.

knockout.js in ruby on rails

knockout.js helps you to simplify dynamic JavaScript UIs using the Model-View-ViewModel (MVVM) pattern.

Key features :

1) Easily associate DOM elements with model data using a concise, readable syntax.

2) Pure JavaScript and works with any web framework.

3) When your data model's state changes, your UI updates automatically.

4) Small and Lightweight.

5) Implicitly set up chains of relationships between model data, to transform and combine it.

6) Supports all mainstream browsers.

7) Quickly generate sophisticated, nested UIs as a function of your model data.

Knockout.js follows Model-View-View Model (MVVM) is a design pattern for building user interfaces.

The official website for knockout.js is http://knockoutjs.com/

Coming to using knockout.js in ruby on rails application. After googling I came to see its been using ruby on rails application with the help of gem 'knockout-rails' https://github.com/dnagir/knockout-rails

Here is one of the useful URL which explains the benefits of knockoutjs over backbone.js
URL:http://jeffdeville.com/javascript-development-and-frameworks


some useful links related to knockout.js with rails Implementation

http://obruening.github.com/projects/knockoutjs/help.html

https://github.com/umamahesh/Knockout-On-Rails

Thank You,
Uma Mahesh.

Wednesday, 15 August 2012

Best SCRUM tools

Hi,

I would like to share few thought on SCRUM tools that are most popular in the Tech world.

Agile methodology plays an important role in the software application development, Its bought a wide difference in the application development strategy.

Here are the few tools I have used till now.

1)  Basecamp  Its a product of 37 signals.

2) JIRA

3) Pivotal Tracker 

Here are few more tools that I have seen.

4) Rally 

Let share your views with the tools you have used, by posting comments to this.

Thank You,
Uma Mahesh.

error installing mysql with native extensions

Hi,

Here is the error with mysql on bundle install in my system


Installing mysql (2.8.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/usr/local/rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql-2.8.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-1.9.3-p194/gems/mysql-2.8.1/ext/mysql_api/gem_make.out
An error occured while installing mysql (2.8.1), and Bundler cannot continue.
Make sure that `gem install mysql -v '2.8.1'` succeeds before bundling.


I have searched in google and came to see its missing some required libraries i.e 'libmysqlclient15-dev'

To install the 'libmysqlclient15-dev' library run the below command,

> sudo apt-get install libmysqlclient15-dev


Now it will solve the above issue.

Thank You,
Uma Mahesh.

cannot load such file -- zlib

Hi,

I have faced issue with zlib while installing rails.

Here is the error

root@umamahseh-desktop:/home/umamahseh# gem install rails

ERROR:  Loading command: install (LoadError)
    cannot load such file -- zlib
ERROR:  While executing gem ... (NameError)
    uninitialized constant Gem::Commands::InstallCommand


I have solved the issue by installing mysql in my system. Use Ubuntu software center for installing mysql client and mysql server.


Thank You,
Uma Mahesh.

Tuesday, 14 August 2012

Installing Ruby On Rails in Ubuntu 12.04 LTS


Hi,

The latest version of Ubuntu 12.04 was relaesed, Ubuntu 12.04 LTS (Long Term Support)

Installing Ruby On Rails is easy and cane be done using RVM.

Here are the simple steps for installation

1) Install CURL
> sudo apt-get install curl

2) Install GIT
> sudo apt-get install curl git-core

3) Install RVM and Dependencies
> curl -L get.rvm.io | bash -s stable

Once that’s done, we’re going to need to add a line to ~/.bashrc file (the file responsible for setting up our bash session) which will load RVM. Do this by running this command in the terminal:


echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"' >> ~/.bashrc 

Then we’ll need to reload the ~/.bashrc file which we can do with this small command:

. ~/.bashrc



4) Then install additional dependencies specified by the RVM
> rvm requirements

The above command will list all the requirements.
> sudo apt-get -y install build-essential openssl libreadline6 libreadline6-dev zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

5) Installing Javascript Runtime
> sudo apt-get install nodejs

6) Install ruby
> rvm install 1.9.3
> ruby -v

Now it should display the ruby version that was installed in your system


7) Install Rails
> gem install rails


Now you are done with Installation of Ruby On Rails in your Ubuntu system. Now you can start creating rails application.


Help full links: RVM Installations - https://rvm.io/rvm/install/


Thank You,
Uma Mahesh.

Saturday, 4 August 2012

Installing RVM in ubuntu

Hi,

Below are the steps to install RVM in ubuntu

curl -L https://get.rvm.io | bash -s stable --ruby
 
Run the above command as root user in console
 
This will install the latest version of rvm and latest version of ruby in your system.
 
Thank You,
Uma Mahesh.
 
 
 
 
 

Wednesday, 1 August 2012

latest version of rails 3.2.7 released

Hi,

Rails 3.2.7 has been released. It has some important security fixes. Below is the reference url

URL: http://weblog.rubyonrails.org/2012/7/26/ann-rails-3-2-7-has-been-released/


Thank You,
Uma Mahesh.

url to latest jquery version

Hi,

Here is the url for the latest jquery file that you required to include in html page for jquery library.

http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

Thank You,
Uma Mahesh.

diplay data in webpage on page load

Hi,

In the webworld, displaying webpage in less time plays an important role. So in many satuations you may required to load the page parts separately i.e through ajax call in the page load.

You can see in many webpage page will be loaded first and parts of the webpage is loaded after that.

This can be done using jquery ".load()" method.

This method will load data from server and place the returned html in the element.


  .load( url [, data] [, complete(responseText, textStatus, XMLHttpRequest)] )

  url =>  url of the request to be send.
  data => data that is sent to server.
  complete => its an call back that will inoke after the load was done.



 ex : $('#content').load('umamahesh/sample.html');


 here 'content' => div id
 url => umamahesh/sample.html


sample code:

<! DOCUMENT HTML>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
</head>
<body>
<h1>Response block</h1>
<div id="success"> </div>
<b>Error block:</b>
<div id="error"></div>
<script>
$("#success").load("success.html", function(response, status, xhr) {

  if (status == "error") {
    var msg = "Sorry but there was an error: ";
    $("#error").html(msg + xhr.status + " " + xhr.statusText);
  }
});
  </script>
</body>
</html>


success.html

<! DOCUMENT HTML>
<html>
<head>
</head>
<body>
<div>
Hi my name is uma mahesh
</div>
</body>
</html>


You can load part of data from the url page as below

$('#content').load('umamahesh/sample.html #data');

When this method executes, it retrieves the content of umamahesh/sample.html, but then jQuery parses the returned document to find the element with an ID of data. This element, along with its contents, is inserted into the element with an ID of result, and the rest of the retrieved document is discarded.


Thank You,
Uma Mahesh.