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???

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...