#7 ✓moved_to_github
Brian McManus

More contextual_views questions.

Reported by Brian McManus | June 10th, 2009 @ 12:55 PM

So I added a nested resource (Screenshots) to my main model. I have contextual_views turned on. When I go to model/[id]/screenshots I get an error because resourcelogic is having rails look for my template in screenshots/model/index.erb.

Is this the expected behavior? I would not consider the parent object to be a "context" in this case. Not to mention that I would have thought at the very least it would look in screenshots/model/root/index.erb?

Now I am using contextual_views so I do have a context for the parent model which I would expect to be respected by the children. Here's what I was expecting but maybe I'm crazy.

Say this is routes.rb:

  map.with_options(:path_prefix => "dashboard", :name_prefix => "dashboard_") do |dashboard|

dashboard.resources :models, :has_many => :screenshots



end map.resources :models, :has_many => :screenshots map.resources :screenshots

So my "contexts" would potentially be dashboard or root.

Assuming contextual_views:
* If I go to model/[id]/screenshots I would think it would look in screenshots/root for index with screenshots scoped to the parent model. * If I go to dashboard/model/[id]/screenshots I would think it would look in screenshots/dashboard for index again scoped to the parent model. * If I go to screenshots/ I would think it would again look in screenshots/root but be scoped to Screenshot instead of the parent model.

Maybe I'm just way off base here and the parent model should really be part of the context but I would think a "screenshot is a screenshot" besides you can check if you have a parent object other ways to figure out if you need to do something different for some reason. If you want to leave the parent model as part of the context then shouldn't it have at least been looking in screenshots/model/root/?

Comments and changes to this ticket

  • Brian McManus

    Brian McManus June 10th, 2009 @ 01:23 PM

    I poked around in the source code and found that this behavior was intentional. It doesn't look like resourcelogic really supports nesting resources inside of a parent object's context right now. I was able to get around it by overriding the context method in my controller and basically chop off the first part where it would normally return the parent model name as the context.

    I still think that a parent object should not be considered a context under normal circumstances because your views should be the same for the most part other than links which there are helpers for that don't depend on context.

    Either way I have a way around it that works so whatever you decide works for me.

    Thanks for the great gems (especially authlogic)!

  • Ben Johnson

    Ben Johnson June 10th, 2009 @ 01:25 PM

    • State changed from “new” to “open”

    Hi, that is the whole point of resourcelogic, it allows you to easily nest resources. You need to do:

    belongs_to :parent
    

    In your controller that is being nested. Are you doing that?

  • Brian McManus

    Brian McManus June 10th, 2009 @ 02:01 PM

    Yup, I've got that in the controller. Not sure if you saw my comment above but I got it working by overriding the context method for my case.

  • Ben Johnson

    Ben Johnson August 7th, 2009 @ 06:34 PM

    • State changed from “open” to “moved_to_github”

    [state:"moved_to_github" bulk edit command]

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Adds context into the RESTful development style.

People watching this ticket

Pages