ユーザーがサインアップすると、財務プロファイルの作成が開始されます。私は WickedWizard gem を使用して、Finances モデルに情報を収集します。Finances_welcomeコントローラーは次のようになります。
def show
@finance = current_user.finance || current_user.build_finance
render_wizard
end
def update
@finance = current_user.finance || current_user.build_finance
@finance.assign_attributes(finance_params)
render_wizard @finance
end
get_started.html.erb ビューは次のようになります。
<%= form_for @finance, url: wizard_path, :method => :put do |f| %>
<div class="field">
What's your <strong>name</strong>?<br>
<%= f.text_field :name %>
</div>
<div class="field">
What's your <strong>birthday</strong>?<br>
<%= f.date_select :birthday %>
</div>
<div class="field">
What's your <strong>zip code</strong>?<br>
<%= f.number_field :zip %>
</div>
<div class="field">
What's in between <strong>your legs?</strong><br>
<%= f.select(:gender, Finance::Gender) %>
</div>
<%= f.submit "Next", class: "btn btn-primary btn-lg" %>
既存のユーザーとして /finances_welcome/get_started を押すと、そのユーザーの既存の Finances モデルからの入力が事前入力され、フィールドを更新できるようになります。
しかし、初めてサインアップするユーザーとして、[次へ] をクリックすると、ページが更新されます。エラーは発生せず、新しい Finances モデルは作成されません。(そのモデルをユーザーに関連付けてもかまいません。)