开发者

Rails 3 , help with setting up a config for a controller

开发者 https://www.devze.com 2023-01-25 04:14 出处:网络
I have the resource photos Currently I have this working: /photos which shows the photos#index controller which is what I want...

I have the resource photos

Currently I have this working: /photos

which shows the photos#index controller which is what I want...

But now I want to also have /projects/2/photos

Which should show photos for that project. Problem is that is pointing to the def index, and somehow I need a s开发者_C百科eparate view for this path.

Thoughts? Thanks

routes:

resources :projects do
  resources :photos,do
  collection do
    get 'newjs'
  end
end


In the PhotosController#index action you can check to see if params[:project_id] is defined -- if it is then you are using the sub-resource. If it is not, you are using the top-level resource.

0

精彩评论

暂无评论...
验证码 换一张
取 消