Ankit Kipl
2012-Jun-07 04:59 UTC
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 %> -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
doeme.meier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-May-02 06:24 UTC
Re: Ruby on rails retrieve data respective from select box to text area
I want to do exactly the same thing.. did you find a solution? -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/_vNByBA_VccJ. For more options, visit https://groups.google.com/groups/opt_out.
Walter Lee Davis
2013-May-02 19:38 UTC
Re: Re: Ruby on rails retrieve data respective from select box to text area
On May 1, 2013, at 11:24 PM, doeme.meier-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> I want to do exactly the same thing.. did you find a solution?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 -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.