POST instead of GET gives 404 (newbie)

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

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

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

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

Hi Fred,

Thanks for your reply.

Reading:
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

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

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

[ … 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

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

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

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

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

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

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