shared items

Sunday, October 21, 2012

MultiSelect in rails with Collection_select

    attr_accessible :model2s, :model2_ids
    has_many :model2s

   belongs_to :Model1

1. Have a model with attr_accessible :model2_ids

2. f.collection_select :model2_ids , Model2.all, :id, :name, {},{:multiple=>true,:size=>5}

The trick is "model2_ids"

Thats it !

Saturday, October 20, 2012

JQuery on Rails 3.0.11

Steps to replace Prototype with Jquery

1. open Gem File
2. include gem 'jquery-rails'
3. bundle install in your rails app directory
4. bundle show jquery-rails
5. rails generate jquery:install [--ui]

If you get invalid spec error while doing bundle install, you could do one of the following
1. Update ruby gems to the latest version
     a. gem update --system


1. Modify the erroneous gem spec reported
    a. Open the file , look for the reported data format error and remove all the time section
          example : 23-10-12 00:00.000000000z   to  23-10-12

That's it !

Friday, October 12, 2012

ROR: Multiple references to the same table in the parent table

class Address < ActiveRecord::Base
  has_many :customersend
class Customer < ActiveRecord::Base
  belongs_to :billing_address, :class_name => 'Address', :foreign_key => 'billing_address_id'
  belongs_to :shipping_address, :class_name => 'Address', :foreign_key => 'shipping_address_id'

Source : Linky

Thursday, October 4, 2012

Call Stored Proc from Java with sql types in Stored Proc Call

        final String typeName = "T_ALL_RECORD";
        final String typeTableName = "T_ALL_RECORDS";

        // Get a description of your type (Oracle specific)
        final StructDescriptor structDescriptor = StructDescriptor.createDescriptor(typeName.toUpperCase(), connection);        
        final ResultSetMetaData metaData = structDescriptor.getMetaData();

        // Call the procedure (or whatever else) that returns the table of a custom type
        CallableStatement cs = connection.prepareCall("{call ult_pkg.get_data_Q1(?, ?)}");
        cs.setString(1, "the_id");
        // Result is an java.sql.Array...
        cs.registerOutParameter(2, Types.ARRAY, typeTableName);