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.
I am still confused about your model relationships. Could you post
the class definitions please showing the has and belongs to
relationships?
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.
One other way to think about this - you shouldn’t need to nest
resources more then one level deep.
You only deal with children in relation to parents and dogs in
relation to children. Separate relationships which can be handled
transparently. Plus the links you have to generate get a lot more
confusing - parents_childrens_dog_path( parent_id, child_id, dog_id)
or some such…
The only reason I am doing it this way is for the current_user. This
is the only way I know how to make sure another user does not see a
record created by someone else. If I knew another way to do this then
I would avoid the nested resources. I can see where my current model
is going to become a pain to manage. If I knew how to do that I would
change my ways. Currently I do:
I know there has to be a better way but I am glad it’s working now. I
am new and am sure as I improve I will discover the appropriate way to
handle this.
MLittle,
I just picked up this thread towards the bottom and thought maybe I
could say one thing.
Don’t ever nest more than two levels deep. I have some amazingly
‘deep’ applications and suffered the pains of hell until I picked up
this important point.
If you are still treading water, send me an email and I’ll send a
routes file that will make this point more clear.
Good luck,
David
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.