# Map.resrouces without create or new action?

**URL:** <https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777>\
**Category:** Rails\
**Created:** [April 24, 2007, 3:21am UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777 "2007-04-24T03:21:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [April 24, 2007, 3:21am UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777/1 "2007-04-24T03:21:17Z")

</div>

Hi

Is there a way to use  
map.resources  
in routes for a controller, but without including the create or new  
actions?

Cheers

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [April 24, 2007, 6:53pm UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777/2 "2007-04-24T18:53:37Z")

</div>

Daniel ----- wrote:

> Hi
> 
> Is there a way to use  
> map.resources  
> in routes for a controller, but without including the create or new  
> actions?
> 
> Cheers

If the controller does not define the methods they will not exist, but  
by default, rails throws and ugly error message. (well no uglier then if  
you had misspelled a URL but…) You might instead what to create these  
methods and simply have them throw a pretty 404 or maybe 401(\<- Some  
REST guru will be able to tell you which code to throw)

John

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [April 24, 2007, 7:31pm UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777/3 "2007-04-24T19:31:38Z")

</div>

Hey Daniel,

As far as I understand it, all you have to do is not define the create  
and new action in your controller.

If those actions are not defined in the controller AND there are no  
“new.rhtml” and “create.rhtml” in the views folder, I think it will  
behave like you want to.

HTH

~Rohith

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [April 26, 2007, 2:18am UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777/4 "2007-04-26T02:18:43Z")

</div>

Couldn’t you just use a before\_filter to redirect to ether a nice  
clean error page or even just use the index action instead?

before\_filter :show\_error, :only =\> [:new, :create]

def show\_error  
redirect\_to plural\_path()  
end

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [April 26, 2007, 2:56am UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777/5 "2007-04-26T02:56:45Z")

</div>

On 4/26/07, Robert W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Couldn’t you just use a before\_filter to redirect to ether a nice  
> clean error page or even just use the index action instead?
> 
> before\_filter :show\_error, :only =\> [:new, :create]
> 
> def show\_error  
> redirect\_to plural\_path()  
> end

Really what I was thinking was to not define routes for non-existant  
actions. But if I can’t turn some of them off then something like  
redirection or a nice error will be sufficient.

Cheers

---

<div class="post-metadata">

**Author:** ![liquid](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/47e85d/32.png) [@liquid](https://www.ruby-forum.com/u/liquid)\
**Post date:** [April 26, 2007, 12:57am UTC](https://www.ruby-forum.com/t/map-resrouces-without-create-or-new-action/92777/6 "2007-04-26T00:57:39Z")

</div>

On 4/25/07, John M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > Cheers
> 
> If the controller does not define the methods they will not exist, but  
> by default, rails throws and ugly error message. (well no uglier then if  
> you had misspelled a URL but…) You might instead what to create these  
> methods and simply have them throw a pretty 404 or maybe 401(\<- Some  
> REST guru will be able to tell you which code to throw)
> 
> John
> 
> –

I guess it is the nasty Error page that I’m looking to avoid. Thanx for  
the  
idea.

Cheers  
Daniel
