# Preferred way to disable parts of a RESTful resource?

**URL:** <https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696>\
**Category:** Rails\
**Created:** [July 21, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696 "2008-07-21T23:36:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [July 21, 2008, 11:36pm UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696/1 "2008-07-21T23:36:51Z")

</div>

Hi all -

I’ve got my RESTful resource all setup. However, there is no editing  
or destroying allowed. What’s the preferred way to disable those?

- remove the action? (don’t like this idea)
- redirect within the action skipping the actual edit/destroy call?
- returning an error? (is there a standard here?)

Thanks!

-philip

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [July 21, 2008, 11:55pm UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696/2 "2008-07-21T23:55:02Z")

</div>

remove the action (method) from the controller. if you don’t want  
code to be executed, don’t provide the code to execute.

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [July 21, 2008, 11:55pm UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696/3 "2008-07-21T23:55:37Z")

</div>

def edit  
render ‘404.html’  
end

def destroy  
render ‘404.html’  
end

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [July 22, 2008, 9:16pm UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696/4 "2008-07-22T21:16:08Z")

</div>

Hi,

According to the HTTP specs, when a particular request method isn’t  
supported for a resource identified by a URI, server should return 405  
HTTP code.

Wojtek

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [July 22, 2008, 6:50am UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696/5 "2008-07-22T06:50:20Z")

</div>

On Jul 21, 2008, at 2:54 PM, jemminger wrote:

> remove the action (method) from the controller. if you don’t want  
> code to be executed, don’t provide the code to execute.

The drawback to this is that a RESTful client isn’t going to get any  
notification about why those actions/verbs don’t work. It would be  
nice to provide an error message of some sort “This functionality is  
intentionally not enabled…” or something.

Doesn’t look like there is a preferred way so I’ll just roll my own.

Thanks for everyone’s replies.

---

<div class="post-metadata">

**Author:** ![phallstrom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@phallstrom](https://www.ruby-forum.com/u/phallstrom)\
**Post date:** [July 23, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/preferred-way-to-disable-parts-of-a-restful-resource/143696/6 "2008-07-23T18:05:40Z")

</div>

Aloha Philip,

We use:

def delete  
respond\_to do |format|  
format.html raise(:method\_not\_allowed)  
format.xml {render :xml=\>exception, :status=\>405}  
end  
end

for any methods that aren’t allowed. As Wojtek said, you are supposed  
to return a 405 on items that aren’t allowed not a 404.

Best of luck,

DrMark

On Jul 22, 9:15 am, Wojciech P. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
