Hope this is going to come out understandable. Right now I have a nested resource within my main rest route - as in: map.resources :candidates do |candidate| candidate.resources :canbackgrounds end The reason I have this setup is because I''m working on a multi part form where I"m giving the user the option to do "sections" at their leisure, etc. So the first section (the main - is candidates) the second section is canbackgrounds. However within the actual canbackground form is a field that is inputted into another model / table. My question then is should I be adding this other model into the nested resources, as perhaps a nested resource within canbackgrounds ? Hope this isn''t all too confusing , I know it is for me :) Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> So the first section (the main - is candidates) > the second section is canbackgrounds. > > However within the actual canbackground form is a field that is inputted > into another model / table. > My question then is should I be adding this other model into the nested > resources, as perhaps a nested resource within canbackgrounds ?Resources provide a way to create groups of related routes. So the question is do you need to manipulate this field? I don''t think it makes sense to define resource for just one field. You will be able to deal with your canbackground attributes in a RESTful way. It is not clear from your question why you want to nest another resource for only one field. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/23/06, Bala Paranj <bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > > > So the first section (the main - is candidates) > > the second section is canbackgrounds. > > > > However within the actual canbackground form is a field that is inputted > > into another model / table. > > My question then is should I be adding this other model into the nested > > resources, as perhaps a nested resource within canbackgrounds ? > > > Resources provide a way to create groups of related routes. So the > question is do you need to manipulate this field? I don''t think it makes > sense to define resource for just one field. You will be able to deal with > your canbackground attributes in a RESTful way. It is not clear from your > question why you want to nest another resource for only one field. >Bala , thank you for responding. What I''ve done or will be doing is defining 5 resources. 4 of which is nested in the first. However in a few of those 4 nested resources, the forms contain input elements for models not currently in those resources. Why do these models exist ? Because i have a number of form elements that are multiple selection lists. So to reference canbackgrounds - in the new form i have a select list , multiple, this is written to the canindustries model. My tables looks like this: (nested resource of candidates -> canbackgrounds | id | candidate_id | somefield 1 10 3 (not sure what to do with this -> canindustries | canbackground_id | candidate_id | industry_id 1 10 4 1 10 7 1 10 9 Hope this explains it better. Let me know what you think...anyone :) Stuart> >-- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
So to reference canbackgrounds -> in the new form i have a select list , multiple, this is written to the > canindustries model. > My tables looks like this: > (nested resource of candidates -> canbackgrounds | id | candidate_id | > somefield > > 1 10 3 > > (not sure what to do with this -> canindustries | canbackground_id | > candidate_id | industry_id > > 1 10 4 > > 1 10 7 > > 1 10 9 > > > Hope this explains it better. Let me know what you think...anyone :) > Stuart >So you basically have values for multiple selection list that is part of the canbackgrounds model. You want to know how to persist these values. Is that your question? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/23/06, Bala Paranj <bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > So to reference canbackgrounds - > > in the new form i have a select list , multiple, this is written to the > > canindustries model. > > My tables looks like this: > > (nested resource of candidates -> canbackgrounds | id | candidate_id > > | somefield > > > > 1 10 3 > > > > (not sure what to do with this -> canindustries | canbackground_id | > > candidate_id | industry_id > > > > 1 10 4 > > > > 1 10 7 > > > > 1 10 9 > > > > > > Hope this explains it better. Let me know what you think...anyone :) > > Stuart > > > > > So you basically have values for multiple selection list that is part of > the canbackgrounds model. You want to know how to persist these values. Is > that your question? >Sorry Bala, I''m truly not trying to be confusing. No, those multiple selection values are going into ANOTHER model. some code to demonstrate - config/routes.rb map.resources :candidates do |candidate| candidate.resources :canbackgrounds end Now from teh canbackgrounds ''new'' form <% form_for :canbackground, :url => canbackground_url, :candidate_id => @candidate_id do |form| %> ..................... <td><%= text_field(:canbackground, :recent_title) %></td> <------------- going to model Canbackground <td><select name=canindustry[category_id][] size="6" multiple="multiple"> <---------- going to model Canindustry <%= options_from_collection_for_select @categories, :id, :name %></select> </td> ............................ Now it''s all working fine as it''s currently set up, however maybe I''m not seeing a better way of doing it. As you said in the first message, for one field it probably doesn''t make sense to create a seperate resource, that''s kind of how I feel. Anyway, hopefully this explains it better. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> Now from teh canbackgrounds ''new'' form > <% form_for :canbackground, :url => canbackground_url, :candidate_id => > @candidate_id do |form| %> > ..................... > <td><%= text_field(:canbackground, :recent_title) %></td> <------------- > going to model Canbackground > <td><select name=canindustry[category_id][] size="6" multiple="multiple"> > <---------- going to model Canindustry > <%= options_from_collection_for_select @categories, :id, :name %></select> > </td> > ............................ > > Now it''s all working fine as it''s currently set up, however maybe I''m not > seeing a better way of doing it. As you said in the first message, for one > field it probably doesn''t make sense to create a seperate resource, that''s > kind of how I feel. > Anyway, hopefully this explains it better. >You can have multiple models in a form. The fields_for helper can be used for this purpose. In this case you can have: <% form_for :canbackground, :url => canbackground_url, :candidate_id => @candidate_id do |form| %> <td><%= form.text_field (:canbackground, :recent_title) %></td> <% fields_for :canindustries do |canindustry| %> <td><select name=canindustry[category_id][] size="6" multiple="multiple"> <%= canindustry.options_from_collection_for_select @categories, :id, :name %></select> </td> I don''t know if there is any other better way of doing this. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/23/06, Bala Paranj <bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > Now from teh canbackgrounds ''new'' form > > <% form_for :canbackground, :url => canbackground_url, :candidate_id => > > @candidate_id do |form| %> > > ..................... > > <td><%= text_field(:canbackground, :recent_title) %></td> <------------- > > going to model Canbackground > > <td><select name=canindustry[category_id][] size="6" > > multiple="multiple"> <---------- going to model Canindustry > > <%= options_from_collection_for_select @categories, :id, :name > > %></select> </td> > > ............................ > > > > Now it''s all working fine as it''s currently set up, however maybe I''m > > not seeing a better way of doing it. As you said in the first message, for > > one field it probably doesn''t make sense to create a seperate resource, > > that''s kind of how I feel. > > Anyway, hopefully this explains it better. > > > > > You can have multiple models in a form. The fields_for helper can be used > for this purpose. In this case you can have: > > <% form_for :canbackground, :url => canbackground_url, :candidate_id => > @candidate_id do |form| %> > <td><%= form.text_field (:canbackground, :recent_title) %></td> > > <% fields_for :canindustries do |canindustry| %> > > <td><select name=canindustry[category_id][] size="6" multiple="multiple"> > <%= canindustry.options_from_collection_for_select @categories, :id, :name > %></select> </td> > > I don''t know if there is any other better way of doing this. >Bala, thank you for the help and responses. You helped clear up my concerns. Stuart -- http://en.wikipedia.org/wiki/Dark_ambient --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/23/06, Dark Ambient <sambient-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/23/06, Bala Paranj <bcparanj-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > > Now from teh canbackgrounds ''new'' form > > > <% form_for :canbackground, :url => canbackground_url, :candidate_id > > > => @candidate_id do |form| %> > > > ..................... > > > <td><%= text_field(:canbackground, :recent_title) %></td> > > > <------------- going to model Canbackground > > > <td><select name=canindustry[category_id][] size="6" > > > multiple="multiple"> <---------- going to model Canindustry > > > <%= options_from_collection_for_select @categories, :id, :name > > > %></select> </td> > > > ............................ > > > > > > Now it''s all working fine as it''s currently set up, however maybe I''m > > > not seeing a better way of doing it. As you said in the first message, for > > > one field it probably doesn''t make sense to create a seperate resource, > > > that''s kind of how I feel. > > > Anyway, hopefully this explains it better. > > > > > > > > > You can have multiple models in a form. The fields_for helper can be > > used for this purpose. In this case you can have: > > > > <% form_for :canbackground, :url => canbackground_url, :candidate_id => > > @candidate_id do |form| %> > > <td><%= form.text_field (:canbackground, :recent_title) %></td> > > > > <% fields_for :canindustries do |canindustry| %> > > > > <td><select name=canindustry[category_id][] size="6" > > multiple="multiple"> > > <%= canindustry.options_from_collection_for_select @categories, :id, > > :name %></select> </td> > > > > I don''t know if there is any other better way of doing this. > > > > Bala, thank you for the help and responses. You helped clear up my > concerns. >Well , now I''m experiencing a problem with this. As for above new/create works fine. Edit though is a problem as the canindustry field in the edit form is not returning the previously selected records. Not sure how to fix this issue. The edit form looks like this: <% form_for :canbackground, :url => canbackground_url, :candidate_id => @candidate_id, :html => {:method => :put} do |form| %> ....fields..... #in the middle is the canindustry field: <select id="canindustry_category_id" name=canindustry[category_id][] size="6" multiple="multiple"> <%= options_from_collection_for_select @categories, :id, :name %></select> </td> The controller has this line for returning teh previously selected fields for canbackground @canbackground = @candidate.canbackgrounds.find(params[:id]) However I have no clue how to pull up the previously stored values for canindustry. Stuart --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---