views:

61

answers:

1

create a blank Rails application and put two files under public foler: file1.html and file2.html.

The contents of file is this

<h1>Post</h1>
<form action='/file2.html' class='openid' method='POST'>
          <input name='openid_username' type='text' />
          <input type='submit' value='Login' />
</form>
<h1>GET</h1>
 <form action='/file2.html' class='openid' method='GET'>
          <input name='openid_username' type='text' />
          <input type='submit' value='Login' />
  </form>

If I click on sumbit for the first form I get

No route matches "/file2.html" with {:method=>:post}):

When I do a get request it works fine. Why is that? I tried this with both webrick and mongrel and the behavior is same.

A: 

You need to setup a route to handle the post. If you run "rake routes" in the root of your project, it will give you a list of all of the routes currently setup and if it's a blank rails project then there will not be a route to handle the post to your file2.html ( although you don't really want to be posting to a static file in public, you should be posting to a controller ). The GET works because it is simply being treated as a static file fetch.

Try http://guides.rubyonrails.org/routing.html

Gordon Robertson
Does it mean that a POST request is never handled by apache or webserver. In this case I assumed that the request will be handled by webserver and rails will not even come in picture.
Neeraj Singh
That's going to depend on how your servers are setup, but you mentioned webrick and mongrel, so if you're running on a dev box and point your browser at something like http://localhost:3000/file1.html, then your /file2.html will become http://localhost:3000/file2.html and be served by the rails process. Which is why you are getting that ( rails ) routing error message.
Gordon Robertson