我正在制作一个Rails 3.1应用程序,并且有一个工作正常的注册表单,但我好像改变了一些东西来打破它..我使用Twitter引导程序和twitter_bootstrap_form_for gem 。我做了一些与表单字段格式无关的更改,但更重要的是,当我提交注册表单以创建新用户时,信息显示在URL中,如下所示:Rails表单发出GET请求而不是POST请求
编辑:这是在最新的Chrome版本和Firefox发生
这里是表单代码:
<div class="span7">
<h3 class="center" id="more">Sign Up Now!</h3>
<%= twitter_bootstrap_form_for @user do |user| %>
<%= user.email_field :email, :placeholder => '[email protected]' %>
<%= user.password_field :password %>
<%= user.password_field :password_confirmation, 'Confirm Password' %>
<%= user.actions do %>
<%= user.submit 'Sign Up' %>
<% end %>
<% end %>
</div>
下面是UsersController代码:
class UsersController < ApplicationController
def new
@user = User.new
end
def create
@user = User.new(params[:user])
if @user.save
redirect_to about_path, :notice => "Signed up!"
else
render 'new'
end
end
end
不知道是否有更多的需要,但如果是这样,让我知道!谢谢!
编辑:为了调试我试图确定:职位,也使用普通的form_for
<%= form_for(@user, :method => :post) do |f| %>
<div class="field">
<%= f.label :email %>
<%= f.email_field :email %>
</div>
<div class="field">
<%= f.label :password %>
<%= f.password_field :password %>
</div>
<div class="field">
<%= f.label :password_confirmation %>
<%= f.password_field :password_confirmation %>
</div>
<div class="actions"><%= f.submit "Sign Up" %></div>
<% end %>
这给了我同样的问题之上。
添加的routes.rb:
Auth31::Application.routes.draw do
get "home" => "pages#home"
get "about" => "pages#about"
get "contact" => "pages#contact"
get "help" => "pages#help"
get "login" => "sessions#new", :as => "login"
get "logout" => "sessions#destroy", :as => "logout"
get "signup" => "users#new", :as => "signup"
root :to => "pages#home"
resources :pages
resources :users
resources :sessions
resources :password_resets
end
我试过指定:张贴无效。我试着用一个简单的form_for。如果您不介意查看,请将上面的代码添加为编辑。仍然有相同的问题.. – kcurtin
你是对的,请原谅我的错字。你可以发布你的'routes.rb'吗? –
没问题,我做了一个编辑,因为我意识到我听起来有点sn :) :) – kcurtin