# POST instead of GET gives 404 (newbie)

**URL:** <https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495>\
**Category:** Rails\
**Created:** [July 8, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495 "2008-07-08T15:36:06Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 8, 2008, 3:36pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/1 "2008-07-08T15:36:06Z")

</div>

Hi,

Using JRuby 1.1 and Rails 2.0, I created a small project in NetBeans  
that allows me to generate a dynamic dialplan in XML. In case it  
matters, I’m using builder-2.1.2 and activerecord-2.0.2.

Going in the browser to:  
[http://localhost:3000/routing/dialplan?Caller-Destination-Number=0](http://localhost:3000/routing/dialplan?Caller-Destination-Number=0)

Does exactly what I want:

However, the arguments (Caller-Destination-Number=0) should be posted  
and that fails. I get a 404.

% curl -F “Caller-Destination-Number=0”  
[http://localhost:3000/routing/dialplan](http://localhost:3000/routing/dialplan)

 Not Found 
# Not Found
 `/routing/dialplan' not found. 
* * *
 WEBrick/1.3.1 (Ruby/1.8.6/2008-05-30) at localhost:3000 

My controller:  
def dialplan  
@routing = Routing.find(:first, :conditions =\> [‘tfn like ?’,  
params[:‘Caller-Destination-Number’]])  
respond\_to do |format|  
format.xml  
end  
end

How do I avoid the 404 and will “params[:‘Caller-Destination-Number’]”  
still work when I use a post instead of a get?

I’ve searched the forums, but am none the wiser and I’ve got no clue  
how to approach this.  
Any help is appreciated.

Thanks, Birgit

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 8, 2008, 4:37pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/2 "2008-07-08T16:37:07Z")

</div>

> How do I avoid the 404 and will “params[:‘Caller-Destination-Number’]”  
> still work when I use a post instead of a get?

Sounds like your routes are setup to only accept a get. params are  
accessed in the same way for gets & posts.

Fred

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 2:28pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/3 "2008-07-09T14:28:32Z")

</div>

Hi Fred,

Thanks for your reply.

Reading:  
[http://api.rubyonrails.org/classes/ActionController/Routing.html](http://api.rubyonrails.org/classes/ActionController/Routing.html)

I’ve tried several things in config/routes.rb, such as  
map.connect ‘routing/dialplan’, :controller =\> ‘routing’,  
:action =\> ‘dialplan’,  
:conditions =\> { :method =\> :post }

but no progress.

Googling for ‘post’ is like searching for a needle in a haystack.  
Would you mind helping out a bit more?

Thanks, Birgit

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 2:32pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/4 "2008-07-09T14:32:20Z")

</div>

On 9 Jul 2008, at 13:16, Birgit A. wrote:

> :action =\> ‘dialplan’,  
> :conditions =\> { :method =\> :post }
> 
> but no progress.
> 
> Googling for ‘post’ is like searching for a needle in a haystack.  
> Would you mind helping out a bit more?

What’s in your routes right now ? If you haven’t gone out of your way  
with conditions on your routes, resources etc… then the default  
controller/action/id route should still catch it whether it’s a post  
or a get.

Fred

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/5 "2008-07-09T15:21:36Z")

</div>

On 09/07/08 13:31, Frederick C. wrote:

> > I’ve tried several things in config/routes.rb, such as  
> > with conditions on your routes, resources etc… then the default  
> > controller/action/id route should still catch it whether it’s a post  
> > or a get.
> 
> Fred

Hi Fred,

Thanks for your reply (again).  
I got it working, albeit in GlassFish (not in Webrick).

My routes.rb files is very basic (I removed the ‘map.connect’ again):

ActionController::Routing::Routes.draw do |map|  
map.connect ‘:controller/:action/:id’  
map.connect ‘:controller/:action/:id.:format’  
end

When I deployed the app in question in GlassFish and I got a different  
error than the one in Webrick when I do a HTTP post (http get was  
stillOK):

% curl -F “Caller-Destination-Number=0”  
[http://apso.westhawk.co.uk:8080/Dialplan/routing/dialplan](http://apso.westhawk.co.uk:8080/Dialplan/routing/dialplan)

[… cut …]

 The change you wanted was rejected (422) [... cut ...] 

# The change you wanted was rejected.

Maybe you tried to change something you didn't have access to.

I noticed in the glassfish/…/production.log:  
ActionController::InvalidAuthenticityToken (No :secret given to the  
#protect\_from\_forgery call. Set that or use a session store capable of  
generating its own keys (Cookie Session Store).):

After googling, I commented out the in app/controllers/application.rb  
protect\_from\_forgery # :secret =\> ‘xxxx’  
line.

It’s a bit of a pain that it doesn’t work in Webrick. It makes  
development harder.

Thanks, Birgit

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 3:51pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/6 "2008-07-09T15:51:26Z")

</div>

On 09/07/08 14:29, Frederick C. wrote:

> > 
> 
> Were you restarting webrick after changing routes.rb ?
> 
> Fred
> 
> > Thanks, Birgit

Hi Fred,

When I first encountered the Webrick problem, my routes.rb was the plain  
default one. Just to be sure, I just added the ‘map.connect’ back and  
restarted webrick. Same problem.

In my Netbeans webrick output window, I get:  
#\<WEBrick::HTTPStatus::BadRequest: invalid body size.\>  
[“/home/birgit/.netbeans/6.1/jruby-1.1/lib/ruby/1.8/webrick/httprequest.rb:288:in  
`read\_body’”,

This might well be a Netbeans/Webrick error, see  
[http://jira.codehaus.org/browse/JRUBY-2446?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel](http://jira.codehaus.org/browse/JRUBY-2446?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel)

I’m not running on a windows platform, but otherwise, the conditions are  
the same: NetBeans 6.1, JRuby 1.1, gems 1.8

Thanks, Birgit

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 4:01pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/7 "2008-07-09T16:01:19Z")

</div>

On 9 Jul 2008, at 14:50, Birgit A. wrote:

> [“/home/birgit/.netbeans/6.1/jruby-1.1/lib/ruby/1.8/webrick/  
> httprequest.rb:288:in  
> `read\_body’”,

> This might well be a Netbeans/Webrick error, see  
> [http://jira.codehaus.org/browse/JRUBY-2446?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel](http://jira.codehaus.org/browse/JRUBY-2446?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel)

Ah yes that does rather look like the same thing. You shouldn’t need  
anything other than the default in routes.rb but if webrick is not  
playing ball then I suppose that’s its fault (or possibly jruby’s fault)

Fred

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 4:21pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/8 "2008-07-09T16:21:26Z")

</div>

On 09/07/08 14:59, Frederick C. wrote:

> playing ball then I suppose that’s its fault (or possibly jruby’s fault)
> 
> Fred
> 
> > I’m not running on a windows platform, but otherwise, the conditions  
> > are  
> > the same: NetBeans 6.1, JRuby 1.1, gems 1.8
> > 
> > Thanks, Birgit

Thanks, Fred, for all your help.  
It’s a bummer, but at least I can do some development using HTTP get and  
test it properly using a HTTP post by deploying it.

Thanks, Birgit

---

<div class="post-metadata">

**Author:** ![Birgit\_SWesthawk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@Birgit\_SWesthawk](https://www.ruby-forum.com/u/Birgit_SWesthawk)\
**Post date:** [July 9, 2008, 3:32pm UTC](https://www.ruby-forum.com/t/post-instead-of-get-gives-404-newbie/142495/9 "2008-07-09T15:32:06Z")

</div>

On 9 Jul 2008, at 14:17, Birgit A. wrote:

> protect\_from\_forgery # :secret =\> ‘xxxx’  
> Ah yes. That only applies to post requests (but you’ll only hit that  
> error after the correct action has been routed too)
> 
> line.
> 
> It’s a bit of a pain that it doesn’t work in Webrick. It makes  
> development harder.

Were you restarting webrick after changing routes.rb ?

Fred
