2011-11-11 111 views
5

我正在製作一個Rails 3.1應用程序,並且有一個工作正常的註冊表單,但我好像改變了一些東西來打破它..我使用Twitter引導程序和twitter_bootstrap_form_for gem 。我做了一些與表單字段格式無關的更改,但更重要的是,當我提交註冊表單以創建新用戶時,信息顯示在URL中,如下所示:Rails表單發出GET請求而不是POST請求

編輯:這是在最新的Chrome版本和Firefox發生

http://localhost:3000/?utf8=%E2%9C%93&authenticity_token=UaKG5Y8fuPul2Klx7e2LtdPLTRepBxDM3Zdy8S%2F52W4%3D&user%5Bemail%5D=kevinc%40example.com&user%5Bpassword%5D=testing&user%5Bpassword_confirmation%5D=testing&commit=Sign+Up

這裏是表單代碼:

<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 

回答

3

的問題是,我是指定當Rails form_for生成自己的HTML表單標記時。見下面添加一個類到表格:

<%= form_for(@user, :html => { :class => "form-stacked"}) do |f| %> 

這工作正常。我仍然不確定爲什麼有兩個標籤會產生一個GET請求。

0

看起來你對被髮送一個GET請求,而一個POST請求。我不知道爲什麼發生這種情況(你嘗試使用普通form_for用於調試目的?),但你應該能夠解決這個問題我明確地設置方法:

<%= twitter_bootstrap_form_for(@user, :method => :post) do |user| %> 
+0

我試過指定:張貼無效。我試着用一個簡單的form_for。如果您不介意查看,請將上面的代碼添加爲編輯。仍然有相同的問題.. – kcurtin

+0

你是對的,請原諒我的錯字。你可以發佈你的'routes.rb'嗎? –

+0

沒問題,我做了一個編輯,因爲我意識到我聽起來有點sn :) :) – kcurtin

相關問題