Hi folks, I''ve done this a few ways that have all seemed a bit ''nobby'' so was just wondering if there is a recommended way to achieve the following: I have 2 models, ''customers'' and ''sites'' which are connected with a has_many/belongs_to relationship. I have the scaffold form which creates customers, which is as desired, but I ONLY want to be able to create a site after going through the :show page of a customer and selecting an ''Add new Site'' link. To do this, I can obviously just provide a link_to to the sites/new controller, but I need to pre-populate the sites ''customer_id'' field, without displaying this in a way that could be manipulated (e.g. in the URL as a parameter). Unfortunately, I do need the ''sites'' form to be on a separate page to the customer show page, otherwise it would have been very easy. Is there a better solution that POSTing to the site form with the values from the :show page, to then POST to the create method? Really appreciate any pointers on this, Paul -- 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.
it sounds like users can only create sites to their own customer records. This is authorization and can do handled with something like the cancan gem. On Thu, Jul 7, 2011 at 5:36 AM, paulo <paul.a.taylor84-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi folks, > > I''ve done this a few ways that have all seemed a bit ''nobby'' so was > just wondering if there is a recommended way to achieve the following: > > I have 2 models, ''customers'' and ''sites'' which are connected with a > has_many/belongs_to relationship. > I have the scaffold form which creates customers, which is as desired, > but I ONLY want to be able to create a site after going through > the :show page of a customer and selecting an ''Add new Site'' link. > > To do this, I can obviously just provide a link_to to the sites/new > controller, but I need to pre-populate the sites ''customer_id'' field, > without displaying this in a way that could be manipulated (e.g. in > the URL as a parameter). > > Unfortunately, I do need the ''sites'' form to be on a separate page to > the customer show page, otherwise it would have been very easy. > > > Is there a better solution that POSTing to the site form with the > values from the :show page, to then POST to the create method? > > > Really appreciate any pointers on this, > > Paul > > -- > 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. > >-- 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.
Sorry, didn''t explain that well; all users have access to all customers and sites, as they manage the customer contracts. As there will be several hundred+ customers, I am just looking for a way to add sites for a customer without having to select the customer each time, instead by accessing the sites/new form through a customer record / show page On Jul 7, 2:07 pm, Noel <wwydi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> it sounds like users can only create sites to their own customer > records. This is authorization and can do handled with something like > the cancan gem. > > > > > > > > On Thu, Jul 7, 2011 at 5:36 AM, paulo <paul.a.taylo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi folks, > > > I''ve done this a few ways that have all seemed a bit ''nobby'' so was > > just wondering if there is a recommended way to achieve the following: > > > I have 2 models, ''customers'' and ''sites'' which are connected with a > > has_many/belongs_to relationship. > > I have the scaffold form which creates customers, which is as desired, > > but I ONLY want to be able to create a site after going through > > the :show page of a customer and selecting an ''Add new Site'' link. > > > To do this, I can obviously just provide a link_to to the sites/new > > controller, but I need to pre-populate the sites ''customer_id'' field, > > without displaying this in a way that could be manipulated (e.g. in > > the URL as a parameter). > > > Unfortunately, I do need the ''sites'' form to be on a separate page to > > the customer show page, otherwise it would have been very easy. > > > Is there a better solution that POSTing to the site form with the > > values from the :show page, to then POST to the create method? > > > Really appreciate any pointers on this, > > > Paul > > > -- > > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.