Ruby on rails retrieve data respective from select box to text area

0 down vote favorite
share [g+] share [fb] share [tw]

I am using rails 3.0.9 and sqlite
I have one form MoaObject in which there are two fields
1. Title (text fields)
2. Description(text area)
I have made controller moa_objects controller and
views(_form,index,edit,new,show) and title and description are added
through form in moa_objects(CRUD)
Now there is another CRUD CompanyMainObject in which I am having above
fields(title,description) and here the title and description should be
retrieve from MoaObject's table..and I want title in selectbox and
description in text area.... I have bring title from moa_objects in
select box...and now my problem is that as soon as one selects title
its respective description should be set in textarea....I have gone to
many blogs but I am not getting any solutions...I have try to use
javascript and retrieve ID bygetselectedindex...but not work...

moa_objects_controller
class MoaObjectsController < ApplicationController
def index
@moa_objects = MoaObject.find(:all)
end

def new
@moa_object = MoaObject.new
end

def create
@moa_object = MoaObject.new(params[:moa_object])
if @moa_object.save
flash[:notice] = "Successfully created product."
redirect_to @moa_object
else
render :action => 'new'
end
end

def show

@moa_object = MoaObject.find(params[:id]) end

def edit
@moa_object = MoaObject.find(params[:id])
end

def update
@moa_object = MoaObject.find(params[:id])
if @moa_object.update_attributes(params[:moa_object]) flash[:notice] =
"Successfully updated product."
redirect_to @moa_object
else
render :action => 'edit'
end
end
def destroy
@moa_object = MoaObject.find(params[:id])
@moa_object.destroy
flash[:notice] = "Successfully destroyed product."
redirect_to moa_objects_path
end

end

form of moa_object
<%= form_for(@moa_object) do |f| %>

<div class="field"> <br>
    <%= f.label :title %><br>
    <%= f.text_field :title %> <br>
</div>
<div>
    <%= f.label :description %><br>
    <%= f.text_area :description %>
</div>

<div class="actions">
    <%= f.submit "Save" %>

</div>
<% end %>

CompanyMainObjectsController
class CompanyMainObjectsController < ApplicationController

def index
@company_main_objects = CompanyMainObject.find(:all)
@moa_objects = Moa.find(:all)
end

def new
@company_main_object = CompanyMainObject.new
end

def create
@company_main_object =
CompanyMainObject.new(params[:company_main_object])
if @company_main_object.save
flash[:notice] = "Successfully created product."
redirect_to @company_main_object
else
render :action => 'new'
end
end

def show
@company_main_object = CompanyMainObject.find(params[:id])
end

def edit
@company_main_object = CompanyMainObject.find(params[:id])
end

def update
@company_main_object = CompanyMainObject.find(params[:id])
if
@company_main_object.update_attributes(params[:company_main_object])
flash[:notice] = "Successfully updated product."
redirect_to @company_main_object
else
render :action => 'edit'
end
end
def destroy
@company_main_object = CompanyMainObject.find(params[:id])
@company_main_object.destroy
flash[:notice] = "Successfully destroyed product."
redirect_to company_main_objects_path
end

end

CompanyMainObject

<%= form_for(@company_main_object) do |f| %>
<%= f.collection_select :object_id,MoaObject.all(:order =>
"id"), :id, :title%>
<%= f.label :description %>
<%= f.text_area :description %>/Now from above selected title I want
respective description/

<%= f.hidden_field :client_id, :value => "#{params[:client_id]}" %>
<%= f.submit "Save" %>

<% end %>

Could you please make a point of quoting all or the relevant bits of the preceding messages when posting to an existing thread? It's incredibly hard for anyone to help you here, since we don't have the context for your question. This is a mailing list, first and foremost, not a forum, even if you may be posting your message from a forum-like Web interface.

Walter