Rails When submitting a form ,always show me the error: Routing Error No route matches "blablabla"
My app is simple :
A controller :"main" with 3 actions : "welcome",开发者_开发技巧"form_receiver" and "result"
and 2 views : "result.html.erb" and "welcome.html.erb"
All I want to do is posting the form in "welcome.html.erb" to the action "form_receiver" and show some result in the "result" action.
But after post the form, I get the error :Routing Error No route matches "/main/form_receiver" ,through I am quite sure that I have include the path in routes.
BELOW ARE MY CODE
controllers/main_controller.rb :
class MainController < ApplicationController
def welcome
#Nothing
end
def form_receiver
@p = params[:customer]
redirect_to :controller => "main",:action=>"result"
end
def result
end
end
views/main/welcome.html.erb :
<h1>Main#welcome</h1>
<%= form_tag :controller => 'main',
:action => 'form_receiver' do%>
<p>name : <%= text_field "customer","nick" %> </p>
<p>pwd : <%= password_field "customer","password" %></p>
<p><input type="Submit" value="sign up"/> </p>
<% end %>
views/main/result.html.erb :
<%=@p['cick']%>
<%=@p['password'] %>
config/routes.rb :
TestForm::Application.routes.draw do
get "main/welcome"
get "main/result"
get "main/form_receiver"
end
As you said, you are posting to form_receiver
. But you wrote get
in the routes.rb.
So you should:
post "main/form_receiver"
精彩评论