生年月日の入力をプルダウンにしようと思って、railsの<%= select :hoge, :fuga, Foo::BAR %>
(hogeはテーブル名、fugaはカラム名、Foo::BARは選択肢を配列にしたものを入れる)
を使おうと思ったら、
テーブルの生年月日のフィールドは1つしか作られておらず使えなかった。
なので直接HTMLを書くことにした。
就職活動SNSなので、18歳未満は登録できない仕様なため、こんな感じにしてみた。
<table class="columns_clear" align="left" style="width:300px;">
<tr>
<td style="width:60px;">
<select id="birth_year" name="birth_year">
<option value="">----</option>
<%- t = DateTime.now.year -%>
<%- t_start = t - 65 -%>
<%- t_end = t - 18 -%>
<%- i = t_start -%>
<%- until i == t_end -%>
<option value="<%= i %>" <%= "selected='selected'" if i == params[:birth_year] %>>
<%= i %>
</option>
<%- i += 1 -%>
<%- end -%>
</select>
</td>
<td style="width:20px;">
年
</td>
<td style="width:40px;">
<select id="birth_month" name="birth_month">
<option value="">--</option>
<%- i = 1 -%>
<%- until i == 13 -%>
<option value="<%= i %>" <%= "selected='selected'" if i == params[:birth_month] %>>
<%= i %>
</option>
<%- i += 1 -%>
<%- end -%>
</select>
</td>
<td style="width:20px;" align="left">
月
</td>
<td style="width:40px;">
<select id="birth_date" name="birth_date">
<option value="">--</option>
<%- i = 1 -%>
<%- until i == 32 -%>
<option value="<%= i %>" <%= "selected='selected'" if i == params[:birth_date] %>>
<%= i %>
</option>
<%- i += 1 -%>
<%- end -%>
</selected>
</td>
<td style="width:20px;">
日
</td>
<td style="width:100px;">
</td>
</tr>
<tr>
<td colspan="7">
※18歳未満の方は入会できません。<br />
※登録後の変更はできません。
</td>
</tr>
</table>もっといい方法ないかな。
お読み頂きありがとうございます。
少しでもお役に立てたらクリックお願いします↓。
