简体   繁体   English

Rails删除某些路由

[英]Rails Remove Certain routes

I have a rails app and I have some custom routes. 我有一个rails应用程序,我有一些自定义路线。 I have a database called Reports. 我有一个名为Reports的数据库。 In my routes.rb i have match '/new' => 'reports#new' however the problem is that /new goes to the right place, but /reports/new is also still active. 在我的routes.rb中我match '/new' => 'reports#new'但问题是/ new去了正确的地方,但/ reports / new仍然有效。 Is there a way to "deactivate" the standard /reports/new so that only /new works? 有没有办法“停用”标准/报告/新,以便只有/新的工作?

Sure, there is. 当然,有。 You can use the only option as in (for example): 您可以使用only选项(例如):

resources :reports, :only => [:create, :edit, :update]

which defines routes only for the specified actions (run rake routes to see all the routes) (so it doesn't remove routes, it just does not generate them) 它仅为指定的操作定义路由(运行rake routes以查看所有路由)(因此它不会删除路由,它只是不生成它们)

Edit: Plus, of course, there's also the except option (also see @Andy Gaskell's anwers) - which generates all routes except for the given actions, see the docs . 编辑:另外,当然,还有except选项(也参见@Andy Gaskell的答案) - 除了给定的操作之外,它会生成所有路径,请参阅文档

If you're only interested in disabling one action except may be more appropriate than only . 如果你只在禁用一个动作兴趣except可能比更合适only It works in a similar way. 它以类似的方式工作。

... :except => :new

http://guides.rubyonrails.org/routing.html#restricting-the-routes-created http://guides.rubyonrails.org/routing.html#restricting-the-routes-created

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM