Solved the problem of rails actioncontroller: methodnotallowed.

Source: Internet
Author: User

Original article, copyright belongs to Hu Tian Fa (hutianfa@163.com) All, reprint please indicate the source:
Http://blog.csdn.net/aidisheng/archive/2008/09/10/2911052.aspx

 

Yesterday I studied the example of using extjs desktop in rails. The official examples are using PHP as a server. It is not difficult to translate PHP into rails. Besides, it is written using rails, the amount of code is only about of that of PHP (of course, it is not easy to translate a sentence, and some database designs need to be modified ). The first problem encountered during the process was that the following exception occurred during the login interface processing:

Actioncontroller: methodnotallowed (only get, put, and delete requests are allowed .):

At first, I thought it was probably because extjs used js to send the request without specifying the method parameter. After carefully checking the code, this was not the case. Later I checked the code online for a long time, most of the information is in English and there is no specific solution.

I have encountered this problem before, but although the project is managed using SVN, there is no detailed solution, this lesson will be learned in the future (of course, this is also an important reason for writing a blog ). The analysis process and solutions are as follows:

First, you must obtain the data sent from the client to the server-view logs:

Processing applicationcontroller # login (for 127.0.0.1 at 2008-09-09 23:06:59) [Post]

Session ID: baw.biikzmxhc2hjqzonqwn0aw9uq29udhjvbgxlcjo6rmxhc2g6okzsyxno

Sgfzahsabjokqhvzzwr7aa ==-- d50a249f3e193b1578c6f971b8e884437ff6caa7

Parameters: {"username" => "Demo", "action" => "login", "password" => "Demo "}

 

The first problem I felt was in the request (parameters: {"username" => "Demo", "action" => "login", "password" => "Demo "}) there is no controller information, so I repeatedly checked the JS Code and found that the path is clear. When I see that the HTTP request has a parameter, my first response is to add another controller parameter. After the parameter is added, the Controller data appears on the server side, but the problem persists.

We will continue to study how parameters are transmitted in other examples. After understanding them, we still cannot find the reason. Back home, after dinner, I plunged into again. When checking the logs, I noticed that the server does not process the request as the controller I wrote, but applicationcontroller. It does not have the login method, and errors are taken for granted.

The real reason is that in the request URLThe correct controller name is not written, so the server is handed over to applicationcontroller by default.. After the correct name is modified, the login function is normal and the desktop is displayed.

Other functions need to be completed in the future.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.