Maybe I'm just going about my application in the wrong way. I'm new with rails and I'm trying to make sure that Child and Dog can only be viewed my the person who creates them. That's how I ended up with resources 3 deep. My resources are actually called User, Child and Parent. User is also current_user (I use restful_authentication) and all the resources are created by the current_user. My routes are basic but are 3 resources deep: User > Child > Parent. So, I reference each in my controllers by current_user.child and when I started trying to access current_user.child.parent, things started to break because I really don't know how to do this. I've read some articles that say more then 1 level deep is not a good idea but I don't how to make sure records aren't viewed by other users that they didn't create. I've bought more book then I probably should and am getting frustrated. Maybe my method of making sure records are not viewed by other users is the wrong approach.
On Sep 18, 2:01 pm, Jeff <cohen.j...@gmail.com> wrote: > On Sep 18, 10:49 am, mlittle <mdlit...@gmail.com> wrote: > > > > > I have nested resources 2 levels deep and am having problems with the > > controller of the deepest resource; > > > Parent > Child > Dog > > > The rails guide says this for the forms, which seems to work fine: > > > form_for [:parent, :child, @dog] > > > I have all the appropriate belong_to and has_many but I cannot figure > > out how to do this in the dog controller: > > > def create > > parent = Parent.find(params[:parent_id]) > > child = Child.find(params[:child_id]) > > @record= parent.child.dog.build(params[:dog]) > > ..... > > end > > > I am getting this error: undefined method `child' > > Not sure what the local variable "child" is doing? It's not being > used in the 3rd line. > > I would have expected the code to look like this: > > parent = Parent.find(params[:parent_id]) > child = parent.children.find(params[:child_id]) > @dog = child.dogs.build(params[:dog]) > > This way, you're making sure that the child you find really belongs to > the parent. Then, you build a new dog for that child's dog > collection. > > Does this help? > > Jeff > purpleworkshops.com --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---