1

ユーザーのメールを受け取るフィールドがあります

<%= 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 %>

ページを読み込むたびに、電子メールのテキスト ボックスが'既に挿入されており、ユーザーはそれを削除して電子メールを適切に挿入する必要があります。

クロムを使用する要素を期待するとき。メール フィールドの値が であることがわかります"'"。どうすれば削除できますか? 前もって感謝します

編集:

ユーザー.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
4

1 に答える 1

1

form_for @user上記の(または同様の)行が必要です。ローカル変数はコントローラーによって埋められます。"'" を埋めるものがある場合はコントローラーのコードを確認し、メール フィールドを "'" に設定するデフォルトがある場合はモデルを確認します。

ユーザー データのスキーマ定義を変更するには、新しいデータベース マイグレーションを作成します。

rails generate migration no_default_for_user_email

これにより、/db/migrate に新しいファイルが作成され、次の 2 つの機能を持つ移行定義が含まれます。

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

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

これにより、データベース定義が更新されます。

于 2012-09-11T11:23:38.147 に答える