开发者

Rails 3 - Couldn't find Photo with ID=quick

开发者 https://www.devze.com 2023-03-23 21:35 出处:网络
I created new model via scaffold and I added new action there - quick. To routes.rb I added get \"photos开发者_开发问答/quick\" and created the file qucik.html.erb (and it\'s in the right view-directo

I created new model via scaffold and I added new action there - quick. To routes.rb I added get "photos开发者_开发问答/quick" and created the file qucik.html.erb (and it's in the right view-directory).

If I will set to browser localhost:3000/photos/quick, I will get the error above. In my controller it looks very simple:

def quick
end

And also in the view:

<div>this is template for quick action</div>

How is possible to get that error message? Why is run show action?

routes.rb:

FirstApp::Application.routes.draw do

  resources :photos
  get "photos/quick"

   root :to => "photos#index"

end


Change routes to use collection and fix the code structure to use the blocks properly:

FirstApp::Application.routes.draw do    
  resources :photos do
    collection do
      get "quick"
    end
  end
  root :to => "photos#index"
end

See some documentation here about such routes

0

精彩评论

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

关注公众号