sarii0213 / karoyaka

0 stars 0 forks source link

formのリファクタ #122

Open sarii0213 opened 1 year ago

sarii0213 commented 1 year ago
# /app/views/done_letting_go_items/_form.html.erb
<% if @to_let_go_item %>
    <%= f.collection_select :reason_id, Reason.selectable, :id, :name, { selected: @to_let_go_item.reason_id, prompt: '手放す理由を選択する'}, { class: 'form-control' } %>
    <% else %>
    <%= f.collection_select :reason_id, Reas on.selectable, :id, :name, { prompt: '手放す理由を選択する'}, { class: 'form-control' } %>
<% end %>

こんな感じに簡潔に書けないかな?

<%= f.collection_select :reason_id, Reason.selectable, :id, :name, { selected: @to_let_go_item&.reason_id || 0, prompt: '手放す理由を選択する'}, { class: 'form-control' } %>