2012-09-11 66 views
1

我有一個字段,需要在用戶的電子郵件Ruby on Rails的:當頁面加載

<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %> 

    <div class = "field">Email: 
     <%= f.email_field :email, :class => "email" %></div> 

<% end %> 

我每次加載頁面email_field已經值插入電子郵件文本框有已經插入一個',和用戶必須刪除它才能正確插入他們的電子郵件。

當我期望使用chrome的元素。我可以看到電子郵件字段的值爲"'"。我如何刪除它?在此先感謝

編輯:

User.rb

class User < ActiveRecord::Base 
    # Include default devise modules. Others available are: 
    # :token_authenticatable, :confirmable, 
    # :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me, :username, :firstname, :lastname 

    # attr_accessible :title, :body 
end 
+1

您是否已經通過應用程序中的任何javascript查看了插入值到輸入字段的任何情況? – jordanandree

回答

1

,你應該有一個以上form_for @user(或類似)線。局部變量由您的控制器填充。查看控制器代碼,如果有某些內容填充「'」或者在有默認值的情況下查看模型,則將電子郵件字段設置爲「'」。

要更改用戶數據的架構定義創建一個新的數據庫mirgration:

rails generate migration no_default_for_user_email 

這將創建一個新的文件/數據庫/與遷移定義遷移具有兩個功能:

def up 
    change_column :users, 'email', :string, default: "" 
end 

def down 
    change_column :users, 'email', :string, default: "'" 
end 

這應該會更新您的數據庫定義。

+0

我正在使用Devise的寶石。據我所知,我的應用程序的設計方沒有控制器。我會發布模型給你看看 – Jazz

+1

@ JamesMcL13看看/db/schema.rb文件。應該有一個用戶表的定義。 –

+0

我發現這行't.string「email」,:default =>「'」,:null => false'。 當我移除數據庫時,它會再次出現''' – Jazz