Wednesday, June 22, 2011

Create Application launcher in Fedora 15

Adding application launcher in Fedora 15 is not easy as previous. I found a better article which shows how to do this.

Monday, January 21, 2008

Creata A Dynamic Controller In Rails

In the web application development , there are some situations where we need to create dynamic controllers . Let me have a chance to explain this further .. We'll take an example and try to understand this situation.
Eg:- Assume that We want to create controllers for each user who registered in our site.
In normal situations , we know how to create a controller ...(ruby script/generate controller Example)
But the example I have mentioned , controller name should be dynamic.

Assume that we are going to create the controller with in the registration method. There for the code to generate the dynamic controller should look like this

Class ExampleController <>

def registration

@user_id=session['user']['id'].to_s()

@user=User.find(:first ,:conditions => ["id=?",@user_id])

@partner=Partner.new(params[:company_details])

if request.post? and @partner.save

user_name=@partner.user_name

system("ruby script/genarete controller #{user_name} index")

redirect_to :controller =>"comman" , :action => "welcome"

end

After creating the controller , you may want to write some codes in to the index method of that controller.
To do that we have to write those codes in the applicaion helper class.

Eg:

module ApplicationHelper

$array=[]


@url=request.request_uri.to_s.slice(1..20)

$company=Partner.find(:first, :conditions => ["url="+ "'"+@url+"'"])

$company_name=$company.company_name

$partner_id=$company.id

$array[0]=$company.id

$array[1]=$company.company_name

return $array

end

After writing the above code ,we can call the index method any view that we want....
Have a Nice Day......!