I'm trying to create a default and disabled 'please select' option for f.select
in simpleform and have selecting an option required. Here's the code:
<div class="form-group mb-3">
<%= f.label :buyer_type, "Which best describes you: " %>
<%= f.select :buyer_type, ['Please Select','Option 1', 'Option 2', 'Option 3'], {}, { class: "form-control" } %>
</div>
I've tried multiple fixes, ranging from prompt:
, required:
, disabled="disabled">Category</option
, include_blank:
and others, but I keep getting a syntax error: "ActionView::SyntaxErrorInTemplate in Users::RegistrationsController#new"
So I've looked in the registrations_controller.rb
file, which has the following code:
# frozen_string_literal: true
class Users::RegistrationsController < Devise::RegistrationsController
before_action :configure_sign_up_params, only: [:create]
before_action :configure_account_update_params, only: [:update]
# GET /resource/sign_up
def new
params[:role] ||= 'buyer'
build_resource
yield resource if block_given?
render "new_#{params[:role]}"
end
def unconfirmed_registration
flash.delete(:notice)
end
#
# def after_sign_up_path_for(resource)
# # '/an/example/path' # Or :prefix_to_your_route
# new_user_session_path(resource)
# end
# POST /resource
# def create
# super
# end
# GET /resource/edit
# def edit
# super
# end
# PUT /resource
# def update
# super
# end
# DELETE /resource
# def destroy
# super
# end
# GET /resource/cancel
# Forces the session data which is usually expired after sign
# in to be expired now. This is useful if the user wants to
# cancel oauth signing in/up in the middle of the process,
# removing all OAuth session data.
# def cancel
# super
# end
protected
# Build a devise resource passing in the session. Useful to move
# temporary session data to the newly created user.
def build_resource(hash = {})
self.resource = resource_class.new_with_session(hash, session)
end
# If you have extra params to permit, append them to the sanitizer.
def configure_sign_up_params
devise_parameter_sanitizer.permit(:sign_up, keys: [:buyer_type, :first_name, :last_name, :registered_as])
end
# If you have extra params to permit, append them to the sanitizer.
def configure_account_update_params
devise_parameter_sanitizer.permit(:account_update, keys: [:buyer_type, :first_name, :last_name, :quality_inspection, :solicitor, :finance, :business_name, :bio, :abn, :registration, :wsite])
end
# The path used after sign up.
def after_sign_up_path_for(resource)
'/welcome'
end
#
def update_resource(resource, params)
if params[:password].present?
resource.update_with_password(params)
else
resource.update_without_password(params)
end
end
#
def after_update_path_for(resource)
edit_user_registration_path
end
def after_inactive_sign_up_path_for(resource)
unconfirmed_registration_path
end
end
So I believe it needs some sort of validation here, or perhaps somewhere else. I've tried including a validation for buyer_type
in the User.rb
, relating to my previous post linked to this one: Creating Required Fields for Website Forms (Simpleform)
I've looked at adding a validation for f.select
using validates :buyer_type
I can't tell where I'm going wrong! Any help would be greatly appreciated!