私のサインアップページは、ユーザーからの入力としてfirst_name
,last_name
、email
、およびaccount_type
を入力します。同じユーザーが自分のプロフィールページを作成すると、:first_name
などのフィールドがすでに埋められて時間が節約されるように、フォームを自動的に入力できますか?Rails自動サインアップと新しいプロフィールで使用される同様のフィールド
Schema.rb
create_table "profiles", force: :cascade do |t|
t.string "first_name"
t.string "last_name"
t.string "username"
t.string "gender"
t.date "birthday"
t.string "email"
t.string "account_type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "handedness"
t.string "coach"
t.date "date_joined"
t.integer "year"
t.string "course"
t.string "main_weapon"
t.string "additional_weapon"
t.integer "cellphone_number"
t.integer "emergency_contact"
t.string "contact_name"
t.string "contact_rel"
t.string "player_status"
t.integer "user_id"
end
create_table "users", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "first_name"
t.string "last_name"
t.string "username"
t.string "account_type"
t.string "security_key"
end
_formビュー:
<%= simple_form_for(@profile) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :username %>
<%= f.input :gender, :collection => ['Male', 'Female'] %>
<%= f.input :birthday %>
<%= f.input :email %>
<%= f.input :account_type %>
<%= f.input :year %>
<%= f.input :course %>
<%= f.input :cellphone_number %>
<%= f.input :handedness, :collection => ['Right','Left','Both']%>
<%= f.input :coach %>
<%= f.input :player_status, :collection => ['Active','Retired'] %>
<%= f.input :main_weapon, :collection => ['Foil','Epee','Saber'] %>
<%= f.input :additional_weapon, :collection => ['Foil','Epee','Saber'] %>
<%= f.input :emergency_contact %>
<%= f.input :contact_name %>
<%= f.input :contact_rel %>
</div>
<div class="form-actions">
<%= f.button :submit %>
</div>
<% end %>
モデルから引き出してフォームに挿入するコントローラ。 – Darkisa
私の最初の質問は、なぜ列名を複製しているのでしょうか?ユーザーが複数のプロファイル(1対多の関係)を持つことは可能ですか? –
いいえ私のユーザモデルに 'has_one:profile'があります – Kevin