开发者

Rails Routing: REST Verb Aliases

开发者 https://www.devze.com 2023-03-12 02:18 出处:网络
Is there an easy way to change the default method that a particular HTTP Verb maps to when dealing with RESTful rou开发者_StackOverflow社区ting in rails? Let\'s say each of my model controllers has a

Is there an easy way to change the default method that a particular HTTP Verb maps to when dealing with RESTful rou开发者_StackOverflow社区ting in rails? Let's say each of my model controllers has a delete action instead of destroy, however when I use:

link_to "Delete", some_object, :method => :delete

Rails does what it's supposed to and routes to the destroy action of my resource's controller. Instead, I'd like to route to an action named delete. That's it.

I know I can just use ruby's alias in my controllers or add a custom member route for each of my resources, but is there an easier way to do this to make the changes app-wide? Thanks!


If you use alias in your ApplicationController, then that will flow through to your other controllers that inherit from it.

That will function the way you want it to.

Warning: rails is opinionated software and generally you won't want to step too far out of the way rails works. And rails loves standard REST actions.

0

精彩评论

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