f.Validation when "Please select" of collection_select is selected

1. What you want to do

<% = f.collection_select: address_id, @ customer.addresses,: id,: full_address,: include_blank =>" Please select "%> I want to apply validation when I select "Please select" at the top without selecting in the form.

2. Implement

app/controllers/orders_controller.rb


 params[:order][:address_id] ==  ""
 flash[:notice] = "Please select"
 redirect_to new_order_path

Looking at the value sent from the parameter, it was " ", so change the equal statement to " ".

3. At the end

When I wanted to implement this, I searched on Qiita and Google, but it did not come out at all. I posted. I keenly realized that I had to look closely at the terminal and check the value returned.

Recommended Posts

f.Validation when "Please select" of collection_select is selected
When the hover of Eclipse is hard to see
When the month of the date is acquired, the January shift