# Action Controller ::MethodNotAllowed

**URL:** <https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075>\
**Category:** Rails\
**Created:** [September 24, 2009, 11:26am UTC](https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075 "2009-09-24T11:26:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/76d3ee/32.png) [@nisha](https://www.ruby-forum.com/u/nisha)\
**Post date:** [September 24, 2009, 11:26am UTC](https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075/1 "2009-09-24T11:26:33Z")

</div>

Hi,

Iam getting the following error

ActionController::MethodNotAllowed  
Only get, put and delete requests are allowed.

Actually, Iam trying to have multiple actions for a form to create  
new record. The actions for the form are cancel, save, publish and  
preview.

here’s the config/routes.rb file code snippet for the relevant  
controller - Events

map.resources :events, :member =\> {:manage =\> :get}, :new =\> {:preview  
=\> :post, :publilsh =\> :post}

The EventsController has functions for new, create, edit, update,  
manage, preview and publish.

the new.html.erb snippet is

\<% form\_for @event, :url =\> events\_path, :html =\> {:multipart =\>  
true, :id =\> “event\_form”} do |f| -%\>  
\<%= render :partial =\> “form”, :locals =\> {:f =\> f} %\>  
\<%= link\_to image\_tag("/images/btn-cancel.png", :border =\> 0),  
dashboard\_path, :style =\> “float:left;” %\>  
\<%= link\_to\_function image\_tag("/images/btn-publish.png", :border =\>  
0), “publish\_event($(this));”, :style =\> “padding-right:20px;” %\>  
\<%= link\_to\_function image\_tag("/images/btn-preview.png", :border =\>  
0), “preview\_event($(this));”, :style =\> “padding-right:20px;” %\>  
  
\<% end -%\>

the javascript functions in application.js

function preview\_event(element){  
element.up(’#event\_form’).writeAttribute(‘target’, ‘\_blank’);  
element.up(’#event\_form’).action = “preview”;  
element.up(’#event\_form’).method = “post”;  
element.up(’#event\_form’).submit();  
element.up(’#event\_form’).writeAttribute(‘target’, false);  
}

function publish\_event(element) {  
element.up(’#event\_form’).action = “publish”;  
element.up(’#event\_form’).method = “post”;  
element.up(’#event\_form’).submit();  
}

Iam stuck with the error. Pls help

---

<div class="post-metadata">

**Author:** ![nisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/76d3ee/32.png) [@nisha](https://www.ruby-forum.com/u/nisha)\
**Post date:** [September 24, 2009, 3:30pm UTC](https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075/2 "2009-09-24T15:30:07Z")

</div>

In routes.rb (for preview & publish), use :any instead of :post, might  
work.

## Thanks, Abhinav

à¤…à¤­à¤¿à¤¨à¤µ  
[http://twitter.com/abhinav](http://twitter.com/abhinav)

---

<div class="post-metadata">

**Author:** ![nisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/76d3ee/32.png) [@nisha](https://www.ruby-forum.com/u/nisha)\
**Post date:** [September 25, 2009, 6:02am UTC](https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075/3 "2009-09-25T06:02:28Z")

</div>

Hi,

Thanks for the reply. But changing from :post to :any didn’t work!!! :  
(  
Is there some other way in which multiple actions for a form can be  
implemented ?  
Any other suggestions are welcome.

Nisha.

---

<div class="post-metadata">

**Author:** ![nisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/76d3ee/32.png) [@nisha](https://www.ruby-forum.com/u/nisha)\
**Post date:** [September 25, 2009, 10:59am UTC](https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075/4 "2009-09-25T10:59:52Z")

</div>

Hi,

Thanks for the prompt reply, but its not working yet!!! ☹  
Any other suggestions.

Thanks,  
Nisha

---

<div class="post-metadata">

**Author:** ![nisha](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/76d3ee/32.png) [@nisha](https://www.ruby-forum.com/u/nisha)\
**Post date:** [September 25, 2009, 7:21am UTC](https://www.ruby-forum.com/t/action-controller-methodnotallowed/176075/5 "2009-09-25T07:21:30Z")

</div>

You can try :member or :collection depending upon your requirements. For  
forms, I guess you should use :member. Read rails guides for more  
details

> **[Rails Routing from the Outside In — Ruby on Rails Guides](https://guides.rubyonrails.org/routing.html)**
>
> Rails Routing from the Outside InThis guide covers the user-facing features of Rails routing.After reading this guide, you will know: How to interpret the code in config/routes.rb. How to construct your own routes, using either the preferred...

## Thanks, Abhinav

à¤…à¤­à¤¿à¤¨à¤µ  
[http://twitter.com/abhinav](http://twitter.com/abhinav)
