Tuesday, October 20, 2009

Released BrokenCompass

So finally after much of ifs and buts and all hesitation have released a version of BrokenCompass.. Full text search engine built using ruby on rails and serving ruby on rails app.

Some of the features which are available as of now in this first release are..
  1. Able to work with all databases for which ruby in rails have no issues(examples shown in links uses mysql)
  2. Availability of extended_mode which allows to search in any particular attribute(from set of attributes which is used while in index creation)
  3. In extended_mode queries can have logical "&"(pronounced as 'and') and "|"(pronounced as 'or') between them(Not operator is not available still, but working out to release in next version).
  4. One can assign weight to set of attributes depending upon requirements and in response get weighted result and also sorted in descending order of weight of record.
  5. By default 20 records are returned as query response(which can be altered)
  6. look_in_brokencompass static method is attached to rails model to get inference of instantaneous parameter set. And to find using brokencompass static method is find_with_brokencompass("searchterm", :brokencompass = {}) and many other..

Here are few links(if interested, will be helpfull)
BrokenCompass: How to go about it
BrokenCompass - Install instructions

Monday, October 19, 2009

BrokenCompass: How to go about it

Once you are done with installation and index creation for brokencompass, can play around with the search capabilities of it..

Point 01. ruby script/console
==> Output
Adding BrokenCompass Version: 1.0
Loading index... [broken_compass/advertisment.index]

Point 02. Searching in all fields, i.e not using extended_mode
Advertisment.look_in_brokencompass("train")
==> Returns an inference hash like this
{
# Time elapsed in the execution(in seconds)
:time_elapsed=>0.00617599487304688,

# Field(s) which is/are available for indexing
:fields=>["location", "title", "description"],

# Weight given to different attributes to ranks result items
:column_weight=>{:description=>10, :location=>10, :title=>10},

# Count of total records found
:total_record_count=>44,

# Boolean field to unload indexes from memory once query is fired
:eager_unload=>false,

# Boolean field for extended_mode, set to true when using attribute(column) level searches
:extended_mode=>false,

# Boolean field for PLURAL forms of search word
:plural_forms=>true,

# Result set with weighted scores
:weighted_records=>[[14844, 20], [17445, 20], ... , [15148, 10]]}

# Limit to result set
:limit=>20,

# Offset to result set
:offset=>0,
}


Point 03. Searching in extended mode i.e specifically in some attribute(from the attributes used in sql query for index creation)
Advertisment.look_in_brokencompass("'job'@title", :extended_mode => true)
==> Returns an inference hash same as above
{
:column_weight=>{:description=>10, :location=>10, :title=>10},
:total_record_count=>1419,
:time_elapsed=>0.0523371696472168,
:fields=>["location", "title", "description"],
:eager_unload=>false,
:limit=>20,
:extended_mode=>true,
:offset=>0,
:plural_forms=>true,
:weighted_records=>[[14607, 20], [17685, 20], ...... , [13727, 10]]
}


Point 04. Searching in extended mode and also using other possible options
Advertisment.look_in_brokencompass("'job'@title", :extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20})
==> Returns an inference hash same as above
{
:column_weight=>{:description=>20, :location=>10, :title=>40},
:total_record_count=>1419,
:time_elapsed=>0.0521509647369385,
:fields=>["location", "title", "description"],
:eager_unload=>false,
:limit=>5,
:extended_mode=>true,
:offset=>4,
:plural_forms=>true,
:weighted_records=>[[17947, 80], [17946, 80], [9597, 80], [12556, 80], [25975, 80]]
}

Point 05. To retrieve data results from above mentioned conditions and critriea
Advertisment.find_with_brokencompass("'job'@title", :brokencompass => {:extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20}})
==> Returns an result-set array of type Advertisment

Point 06. To user "and" & "or" operators in extended mode
Advertisment.look_in_brokencompass("'job'@title | 'career'@description", :extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20})
==> Returns an result-set array of type Advertisment
Advertisment.look_in_brokencompass("'job'@title & 'career'@description", :extended_mode => true, :offset => 4, :limit => 5, :column_weight => {:title => 40, :description => 20})
==> Returns an result-set array of type Advertisment

In case of any further queries please contact me at praveen[dot]kumar[dot]sinha[at]gmail[dot]com

BrokenCompass - Install instructions

BrokenCompass up and running in flat 5 mins

Step: 01
Install BrokenCompass plugin
ruby script/plugin install http://brokencompass.googlecode.com/svn/trunk
from inside of rails app root directory.

Step: 02
Add BrokenCompass configuration yml file
Create file
config/brokencompass.yml

Add content like
#brokencompass.yml............. STARTS
index-sources:
advertisment:
sql: "select id,title,description,location from advertisments"
table_name: advertisments

query:
sql: "select id,content,dynamic_fields from queries"
table_name: queries

# Database connection adapter
connection_adapter:
adapter: "mysql"
host: "localhost"
username: "username"
password: "password"
database: "myapp_development"

#brokencompass.yml............. ENDS

Note:
0. Nothing is optional in the yml(everything is mandatory)
1. Add as many items in index-sources as you want, but every item name should match model names(for which they will be used).
2. Make sure to include the Id field so that index created can be mapped to record identifier.
3. Provide the connection adapter details in connection_adapter section(so as to answer, where to read data from)
4. If you are not minding the spaces in yml(then you have messed up the configuration, so don't try to remove spaces :) from yml, wanna know more about yml? )


Step: 03
Run rake task to create indexes for the first time
rake brokencompass:create_index
from inside of rails app root directory.

Step: 04 (This is required, when one is re-creating the indexes from scratch)
Run rake task to re-create indexes
rake brokencompass:index
from inside of rails app root directory.

Step: 05 (To delete any of the indexes so created, delete corresponding "xxxx.index" file from broken_compass
from inside of rails app root directory.

Friday, October 9, 2009

BrokenCompass

New in-memory full text search engine in ruby and in rails "BrokenCompass".
Coming soon....
keep an eye on this space..

Wednesday, July 29, 2009

svn: This client is too old to work with working copy

Hello folks,

I am still very much alive, i don't know ho missed me or not(am sure no one :D). There is lot happening in life now-a-days will talk about it later, first a quickie about SVN.

If you are working on some project then you must be aware of something called SVN, it is an open source version control system. Recently got hit with something really weired.

I work on Ubuntu but as my ubuntu doesn't have anything even close to 80% of tortoise SVN i tried using windows for that(using virtual windows and samba) to carry on my SVN activities that is really really easy when it is done using TortoiseSVN.

But the time i tried "svn update" from Linux shell command it gave me
praveen@praveen-laptop:~/NetBeansProjects/projectone$ svn update
svn: This client is too old to work with working copy '.'. You need
to get a newer Subversion client, or to downgrade this working copy.
See http://subversion.tigris.org/faq.html#working-copy-format-change
for details.


And i was like what to do now, so followed the instruction and it worked(at least worked for me :) ). So what i did is
Step 01: Downloaded a file http://svn.collab.net/repos/svn/trunk/tools/client-side/change-svn-wc-format.py http://svn.apache.org/repos/asf/subversion/trunk/tools/client-side/change-svn-wc-format.py
Step 02: Executed the following command
praveen@praveen-laptop:~$ python change-svn-wc-format.py /path/to/project 1.5
i.e my project got downgraded to version 1.5

And it worked :)

AS NOTE: usage: change-svn-wc-format.py Working_Copy SVN_VERSION

Next Time something like this happens, you know how to do it.

Monday, June 1, 2009

How to run GPRS from airtel on ROKR E6 motorola

Hey hi guys and gals,
Just after a long time i am writing something on mobile device, actually it is something which shows how stupid I am :D
I was planned to go for a small trip to my home town (I will write a post about it too, but for the time being 'the issue').
I live in Delhi(India) and so this is something for the locale or some one who is facing almost the same that i faced about a week ago, and it was of how to make GPRS active on my best Motorola rokr e6(where it is very much assumed that i have an Airtel post paid mobile connection). I was in urgent need of some way or the other to connect to net as have lot and lot of dependency on it and even if i am off from office i have work to do :D (sounds as if i am very busy person, let me be :D) so i opted for GPRS from my mobile and i know e6 comes with GPRS features, but some how or the other it was not working.
I asked airtel people about it, they were just resending the setting to my phone, which was very much accepted and installed too but the main issue was still there "GPRS was not working", according to them this is all they can do and there was actually not in that, they were sending a GPRS connection premade with the name of "Mobile-office" which contained an APN: airtelgprs.com and an primary gateway ip: 202.56.231.117 and the port was 8080 and nothing more nothing less but damn it was not working, call center executive were helpless what to do so again and again tried different hooks but nothing worked out and i again called the executive and she said something which made me feel how stupid of me, being so much in technology was not able to figure out this small thing and it was that i have to manually enable the GPRS, which is manually accessed from the bar which shows the reception quality, programs and players running and which by default is placed just below the top set of icons, enabled the GPRS from there and restarted my phone(which call center guys usually asks to do) and it worked :)

Sometimes even i can skip something which is right in front of my eyes or one can right in front of my screen (it happens with developers).
So guys or gals if you have faced something stupid like this please comment and let every body know :), at least i did
chow people it is the to hit bed, I am dead tired right now after this vacation :D

Friday, May 8, 2009

Some life updates

Actually this month is happening... as life is as usual.
Just resigned from MPST(MPS Technologies Limited) and am stretching my legs and thank god that even summers are chilling now-a-days so it is all very pleasant.
and I voted too this central elections (it is only applicable if you known about current Indian political status of India).
And ya the most happening thing that i did this week was i took the test drive of Toyota innova, and to be fare i thought i was disappointed for the gear knob vibrations from toyota but latter on, i thought every other car is only way behind it.... so why give it a bad name.. so it is good and perfect if you care about your family and wanna visit places.. it is a nice car that's for sure.
And as was expected, I also visited the tata showroom to ask in for tata most famous car after nano, exactly the safari The tata safari... and not going against my expectations, they didn't had any car to give the test drive and according to them they give test drive on vehicles which are ordered for other customers, now that's bad.
And here is a car comparison that i have not done before..
Innova is
  • good interiors
  • good exteriors
  • not so good vibrating gear in diesel
  • it doesn't rules the road
  • No 4*4 wheel drive
  • but very stable and great family car
  • Service is prompt i will buy innova if i can park it in near future

About Safari
  • "Reclaim you life" slogans fits in, but is life so lost??
  • Great exteriors and equally bad interiors
  • finish is not finished yet, come on guys increase the price by 2 lakhs but don't decrease the expectations
  • Why is roof mounted AC looks as if it is not part of roof (learn something from innova)
  • Service (Needs a big big improvement)
  • And please do have a separate car to test drive

:)

I was so mentally boosting myself to buy a safari but they have shattered my dreams, what to do and why to do!! both questions are playing

Any how people its late in night and that too of no-work... i want to fit my "Reclaim your sleep" slogan now.

bbye and good luck

Saturday, May 2, 2009

Pretty urls with name or title in ruby on rails

Hi folks,

Something on which is very old.. might not be very interesting for many of you who are into rails development. I am talking about the pretty-urls the SEO stuff(forget all this, it is for good readability of url).

So what my basic funda that i have gathered from last three years is that, every resource is identified by an identifier in rails(generally called id, in terms of database), but displaying the id doesn't sounds legal to me.. so to hide the ids and to have a nice looking readable

we can have title or name fields in the database's relation(table) and to make use of pretty urls, we make corresponding column like stripped_title or stripped_name.
create a file "make_pretty_url.rb" in initializers in config and append the following code.


puts "===================================================="
puts "Adding engine to make pretty url(s)"
puts "===================================================="
module ActiveRecord
class Base
after_create :make_or_update_pretty_url_name

def make_or_update_pretty_url_name
parent_column = nil
stripped_column = self.attributes.collect {|x| x.to_s.include?("stripped_") ? x : nil}.flatten.compact.first
if stripped_column
parent_column = stripped_column.gsub("stripped_","")
if self.send(parent_column)
self.send("#{stripped_column}=",stripp_it(self.send(parent_column)))
if self.class.find(:all, :conditions => ["#{stripped_column} = ?",self.send(stripped_column)]).length > 0
self.send("#{stripped_column}=","#{self.send(stripped_column)}-#{self.id.to_s}")
end
self.send("save")
end
end
end

def stripp_it(str)
str.strip.downcase.gsub(/[^a-z0-9]/,"-").gsub(/(-)+/,"-").gsub(/(-)+$/,"")
end
end
end


it will automatically create stripped_{column_name} and will take care of duplicates and instead of using find_by_id(), find_by_stripped_{column_name} will be used to get the resource and "make_or_update_pretty_url_name" method will also be available for any manual work too.

Hope this just adds in the knowledge base of stuff, and if there is anything about it, let me know through comments..

Friday, April 17, 2009

RAILS: interning empty string

Hi folks,

Really after a long time, writing a post on ROR (even a simple post). AN the reason for delay.. work as usual and secondary i want people to educate on an error, with the statement as "interning empty string" something showing thing like this.


Being from IT industry and not much into literature, first thought came in my mind after hitting this error was "what does interning means?" and the answer from dictionary.com says "to restrict to or confine within prescribed limits" which just meant some breakage of boundary of something and i am the culprit( as always :)) )

But an ware of what i did, started hitting Ctrl + Z (to undo my bad deeds :))) but no luck!! just nothing.. i was like what!! what is that which is not getting undone over here and even google search was showing some very unresponsive result... so was left alone to trigger army against this.
And finally i got the answer and it was...

If you have a partial defined something like "_partial_name.html.erb" everything is fine till the time you don't append an extra dot to the partial file name something like "_partial_name..html.erb" it will through "interning empty string" even if you don't render the partial anywhere


So guys and gals next time try to be more concentrated on renaming a partial, because it can lead to something where even google searches don't have a definite answer to.

That is it for the day.

Happy coding and happy engineering

Tuesday, March 31, 2009

Thursday, March 26, 2009

send_file or send_data in link_to_remote

Hi guys,

really really long time i did anything here :).. and no this time not an usual bhaana(excuse) will do but an genuine reason.. was busy building something good.. and it is a secret(just can't disclose it here like this).

Anyhow coming to point.. i was doing a general routine development task for my company and i got hit by a situation like this.. where i was making an ajax call to a controller/action and in response i was sending a stream i.e (send_data and send_file) but as the post was xmlhttp everything was working fine but download was not available (and yeh over here i coded it for download not the inline stuff). What to do now.... i searched it ya ya googled it and response was not a solution that i can rely on(it might not be google's fault must be mine, but why am i favoring it.. it must be google fault lol :)) )

So i solved it my own way by redirecting the update to other action and coding the stream in the newly redirected action :)

Here are some snippets of it....

<%=link_to_remote "Export the result",:url => {:controller => "some_controller", :action => "ask_to_export"},:with => "'record_ids=1-2-3-4-5-6'" -%>

def ask_to_export
render :update do |page|
page.redirect_to :action => "process_and_export", :record_ids => params[:record_ids]
end
end

def process_and_export
outfile = ""
CSV::Writer.generate(outfile) do |csv|
csv << ["praveen","kumar","sinha",1,2,3,nil,""]
end
send_data outfile, :type => 'text/csv; charset=iso-8859-1; header=present', :disposition => "attachment; filename=report_#{Time.now.to_f.to_s}.csv"
end

I hope this must be helpful to some one stucked over here and googling it

Thanks :)

Sunday, March 8, 2009

NetBook ASUS EeePC

O my god!!! i got this small little machine.... the coolest gadget till yet. and have some snaps ....



Tech specs are intel Atom Duo, 2 GBytes of Ram, the ddr2 one and the sleek and so bright 10 inches screen
and only 5% keyboard is what it all sacrificed it for this look.. apart from the optical drive and now i have to do something to not to miss it :))

Earlier had one dell but due to some faults in the system
its wifi stopped working and its Ram was Half of Gb and its upgrading was costing me about Rs. 2200.00, which was a bit more than i actually expected so i went to NehruPlace and changed the system it self and got this new stylish looking baby... it will do my needs and it is quite a bit handy too so small in dimension and good enough battery life of about 5 hrs and keyboard is not bothering me too either although its right shift key is a bit awkwardly placed :)

I am looking it for some more stuff to get onboard but that will be something which i think is an ongoing process for a person like me :)

That is it of for me.. the biggie news of the week

Monday, February 23, 2009

SSL and RubyonRails

Hi guys and gals too :),

Am back after a fair long interval this time, ya ya same old reason was busy with office and all. But recently did something good(if not unusual).
And the heading is telling it very correct, did implemented the SSL and used https for some of my pages in rubyonrails.

As many of my readers know, i am new to ubuntu so is new to apache too(initially i used to think, these dealings are sort of system admin stuff) but hey after all it is a software and some bit of configurations.. so i thought lets do it.. and i did it...

So now trimming all the conversation.. the aim of my application was to implement https(SSL) for the "payment gateway" and "pick package" page
and here is the solution
for the prerequisite purpose i assume that you have apache and ruby on rails setup in your system and you have an ROR application which needs https protocol for some of the pages

Step 00: Create a ssl certificate signed by yourself (by following these steps)
install the ssl-cert package
sudo aptitude install ssl-cert

# to create a self-signed certificate.. it will open several dialog boxes, keep on answering the question in correct format(some 7-8 inquiries are there) and at the end you will have your self-signed certificate
sudo make-ssl-cert /usr/share/ssl-cert/ssleay.cnf /path/to/ssl/certictare/selfsigned.pem

Step 01: first of all enable the modes(for apache)
sudo a2enmod ssl
sudo a2enmod proxy
sudo a2enmod rewrite
sudo a2enmod proxy_balancer
sudo a2enmod proxy_http
sudo a2enmod headers


Step 02: set the virtual host
goto apache root directory(which is at /etc/apache2 in my case) and execute following commands
#to switch to apache directory
cd /etc/apache2

#to disable the default site(which have the default configuration of apache)
sudo a2dissite default
#create a new configuration for virtual host by copying the default site configuration and (rename 'ourapplication' with your application name)
sudo cp sites-available/default sites-available/ourapplication
#to enable our application site configuration in apache
sudo a2ensite ourapplication

Step 03: edit the newly created ourapplication configuration, which is available at /etc/apache2/sites-available/ourapplication using any of your favorite editor
sudo gedit /etc/apache2/sites-available/ourapplication


and it should look something lie this
<VirtualHost *:80>
ServerName ourapplication
ProxyPass / http://somename.com:3000/
ProxyPassReverse / http://somename.com:3000/
</VirtualHost>

<VirtualHost *:443>
ServerName ourapplication
ProxyPass / http://somename.com:3000/
ProxyPassReverse / http://somename.com:3000/
ProxyPreserveHost On
RequestHeader set X_FORWARDED_PROTO 'https'

SSLEngine On
SSLProxyEngine On
SSLCertificateFile /path/to/self/signed/certificate/selfsigned.pem
SSLProxyMachineCertificateFile /path/to/self/signed/certificate/selfsigned.pem
</VirtualHost>


Step 04: We also have to change the proxy configuration, so that proxy request can be handled as we desire it to do
sudo gedit /etc/apache2/mods-available/proxy.conf

change the setting from
previous proxy setting
<proxy>
AddDefaultCharset off
Order deny,allow
Deny from all
Allow from .example.com
</proxy>
to new proxy setting
<proxy>
AddDefaultCharset off
Order deny,allow
Allow from all
</proxy>

Step 05: To reload the new setting so that apache can follow our rule..
sudo /etc/init.d/apache2 force-reload
(but it should not give any error, and it will not if no wrong is done to it form the above mentioned procedures)
if it gives some ouitpit like this
* Reloading web server config apache2
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

Step 06: Now all apache work is done, you had to do small amount of effort in your rails application and here they
a) install a plugin
ruby script/plugin install ssl_requirement

b) include it in the application controller so that it can use ssl using
include SslRequirement

c) to use https on any particular action of some controller use
class EcommerceController < ApplicationController
ssl_required :action_name_1, :action_name_2, :action_name_3
# some more codes..............
end


if you have any query just drop me a comment, otherwise all is well as expected :)

Monday, February 16, 2009

visit to surajkund mela

Recently visited the surajkund mela @ faridabad, India.
I am as such reluctant to visit places with crowd but this time it was different[it was the valentine day after all :) ]. i have just uploaded the picture slideshow on slideshare.net

Tuesday, February 3, 2009

form inside form. is it possible?

Hi guys,

whatever i can recall i think i got hit by this problem earlier too, but at that time certainly i was not a blogger, in fact i was lazy of writing too :)) and see it came again, this issue is of placing a html form inside another.
It sounds messy right?? ya ya i know, but some how this was one of the requirement for one of the application that i was developing.

was having a html form with list item as radio box option but later it came to the requirement that label of radio button too should be update able so i tried putting up form_remote_tag(the rails method) for labels but it was not working in fact html form was not coming on to the page(as i was loading it through partials).

So went in for :with parameter in using the remote functions for prototype helper

the host rhtml
<% form_tag url_for(:controller => "controller_name", :action => "action_name") do %>
<%@some_collection_hash.each do |key,value| -%>
<span><%=key%></span>
<%value.each do |single_item|-%>
<div class="sbc" style="width:30px;">
<%=radio_button_tag("publisher[#{key}]", single_item.id,false,:disabled => (single_item.status != "valid")) -%>
</div>
<div class="sbc" id="<%=single_item.id-%>_batch">
<%=render :partial => "/xyz/partial_one", :locals => {:single_item => single_item, :key => key} -%>
</div>
<%end-%>
<%end-%>
<%= submit_tag "Get Summary"%>
<% end %>

The view partial
<ul>
<li class="head_li">Satus:</li>
<li class="dotless_li">
<%=select_tag("#{single_item_id}_status", options_for_select(["valid","invalid","pending","running","deleted","summarize"],@single_item.status)) %>
</li>
</ul>
<ul>
<li class="head_li">Description:</li>
<li class="dotless_li"><%=text_area_tag "#{single_item_id}_desc", @single_item.comments, :rows => 3, :cols => 30 -%></li>
</ul>
<input type="button" value="Close" onclick="<%= remote_function(:update => "options",
:url => {:controller=> :controller_name, :action => :show_single_iteminfo ,:single_item_id => single_item_id, :key => key},
:update => { :success => "#{single_item_id}_single_item", :failure => "#{single_item_id}_single_item" }) -%>" />

<input type="button" value="Save" onclick="<%= remote_function(:update => "options",
:url => {:controller=> :controller_name, :action => :save_single_iteminfo ,:single_item_id => single_item_id, :key => key},
:with => "'description='+$F('#{single_item_id}_desc')+'&'+'status='+$F('#{single_item_id}_status')",
:update => { :success => "#{single_item_id}_single_item", :failure => "#{single_item_id}_single_item" }) -%>" />

Saturday, January 31, 2009

Will you call this evolution ? switched to ubuntu linux


Hi guys,

am back again and guess what writing it form the firefox running in ubuntu.. and this time no escape please.. i made very much mandatory that i should not have any door that i can look back a way to windows xyz... no i am not getting harsh on it just a bit more infatuated towards my new hardy.... yippee its running and running fine if not perfectly fine.. but who said i am looking in for perfectness after if i am believer of 80:20 rule i am very happy really very satisfied with it.

Last night was chatting to one of my friend(pravesh) and when he got to know about it he said he still remember those MCA college days where i use to favour windows and he was one of few who use to be on Linux side.. at those time we use to have system but almost zero Internet connectivity (as if, Internet world has no open doors for us at those time :)) )

and still i am backing those thoughts(adial tattu sort of stuff) because whatever i have evolved in today it is all because windows was there and it helped understand me the words like 'os' and 'system' to me(it is said that it is the first step which is toughest to achieve after that evolution will take you on) and it happens with almost all of us here in India.

so ending the flashback.. current scene is that i am running my work on

hardy ubuntu 8.04 and it is running fine dear.

installing running ruby,mysql,subversion, rails and many other application was quite a breeze through 'apt get'. also installed picasa for ubuntu and netbeans. one issue is running with netbeans, it is somehow interfering or getting interfered with the glossy effect so have to swicth the effects in appearance(thats what i found for the issue with netabens when no controls was visible in interface)

rest is all good it has just been about 5 days on to ubuntu and as there is no windows in my system now so any problem and issue will be tackled in ubuntu way only.

a system which gets installed in about 30mins time and with all office software installed and which looks good and is simple to use, obvious stuff is available and one needs not worry about anything as there is plenty full of support and help on net(unless for you doors are not shut yet) this Linux from ubuntu is good and if planning to switch to ubuntu but is/was doubtful about its driver compatibility and all and its response to you i will say mark my words you will not feel the pane in fact you will learn a lot.

post is really grown very long.. but koi issue nahin hai ji sometimes even i can write right???

Thursday, January 22, 2009

Group controllers/views in RubyonRails

Hi guys,

It has really been a long time since i blogged about something from ruby on rails corner.. and so here is one.

Recently, have been asked to merge to rails application in one. Meaning to merge the code base so that they can become an single application but to maintain the readability i thought of keeping the code base some how segregated. So initially the idea was of making a plugin of application which is to be merged with main application and with the use of rails-engine plugin that would have been easy(at least that i thought of) but see the dilemma i was not even able to run the demo plugin(with the use of rails-engine) and as time was constraint too i thought of dropping the idea and doing some thing easy which can do the work and also in less time.

Then came the idea of grouping controller, views, helpers, layout, model etc... all in different folders and i was able to segregate controller, views but not models(anyone with solution/thought on it please comment).

Static view of segregated 'controllers'


Static view of segregated 'helpers'


Static view of segregated 'views'


Now that i have shown you the file positions.. what is the code which does the trick!! The answer is, when one creates a folder inside controller's folder in rails application, it makes a module of it and one should make the controllers belong to this module other wise those controllers will not be available.

class AuditTool::BaseController < ApplicationController

end

this acts as application controller(which is derived for the main application-controller) to the segregated controllers and other controllers could be derived from this base controller, like this


class AuditTool::BatchesController < AuditTool::BaseController
layout "/audit_tool/layouts/main"
def index
# line(s) of code.................
end
def list
# line(s) of code ...............
end
end


and helpers looks like this

module AuditTool::BatchesHelper
def function1(processed_on,label = "earlier")
# line(s) of code ...............
end
def function2(processed_on,label = "earlier")
# line(s) of code ...............
end
end


and getting spoon feeding the head section of layout goes like this

<%=stylesheet_link_tag("audit_tool/style")-%>
<%=stylesheet_link_tag("audit_tool/style_new")-%>
<%=javascript_include_tag :defaults-%>
<%=javascript_include_tag "audit_tool/slider.js"-%>
<%=javascript_include_tag "audit_tool/custom_1.js"-%>

link to controller/action of segregated controller is written like this

<%=link_to "Report Audit", {:controller => "audit_tool/reports" , :action=> "index"} -%>

link to main controller/action from inside of segregated views is written like this

<%=link_to "Got to main app", {:controller => '/admin', :action => 'dashboard' }%>


the post has started looking long, i thing i should stop it here only....
anybody with thoughts on this with any prospective do comment ( after all knowledge is sharable)

Monday, January 12, 2009

Whenever i am getting the scolding, its not me its you

Hi guys,

Recently hear ed this compliment :)) (I am referring to the heading of course) and i took it as compliment. Anyhow jokes apart.. last week it has been happening time... got to know and personally meet people who read my blog(for whatever reason) and you know what they liked it!!! and the complement factor was ,they asked it to also mention in my r****e .

Also signed in for twitter and i personally had no plans to do so but so many times people asked me have you used it??? i told to myself what is that people are talking about it so much.. and how i felt after it is in next line but i personally know guys who made some thing similar to this called kwippy( and the time when they introduced it to me i said is it really a need) and still the question remains the same is it really in need (to twitter people), but the truth is that now i am on it :)

A very Happy Lohri readers.. I kept this post in draft fridge for a day and now its LOHRI and next it is going to be Makar Sankarnti.. back to back festivals (really a delight for a foodie like me) :)


And one more thing.. was going in to gurgaon at an evening from my place and saw this beautiful sunset(mark me sorry for not carrying a good camera.. i have a phone and it can only solve this much of the problem) but believe me it was very nice than what you are getting in here in this snapshot above.

Friday, January 2, 2009

Too much thinking 'can make you fat'

No wonder i am getting my bear belly growing king size :)) 
Recently stumbled on this site and now i know, whom to blame and what for!!

Honda Civic & A/C problems.

Hello Friends, Got a post again on to Honda Civic (The good old favorite commuter of mine). This car has been doing great except for so...