I want a user (candidate
) to select his skills (like python, rails, node..) while he is signing up.
I know I can use the following:
new.html.erb
<%= f.select(:skill, [['Python', 'Python'],
['Java', 'Java'],
['Rails', 'Rails'],
],
{ :multiple => true, :size => 5 }
) %>
BUT
What if I want the user to add a custom field?
Imagine the user has also the skill Javascript
. As it is now, he cannot selected it.
How can I allow him to add a custom field in the f.select
?
schema.rb
create_table "candidates", force: :cascade do |t|
t.string "email", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "reset_password_token"
t.datetime "reset_password_sent_at"
t.datetime "remember_created_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "skill"
t.index ["email"], name: "index_candidates_on_email", unique: true
t.index ["reset_password_token"], name: "index_candidates_on_reset_password_token", unique: true
end
I tried
<head>
<script>$( "#user_organization_name" ).keypress(function() {
$('#custom_org_id_select_menu').removeClass();
});</script>
</head>
<h2>Sign up for candidates</h2>
<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :email,
required: true,
autofocus: true,
placehoder: "name@gmail.com",
input_html: { autocomplete: "email" }%>
<%= f.input :password,
required: true,
hint: ("#{@minimum_password_length} characters minimum" if @minimum_password_length),
input_html: { autocomplete: "new-password" },
placeholder: "xYui6578Z!"%>
<%= f.input :password_confirmation,
required: true,
input_html: { autocomplete: "new-password" },
placeholder: "Repeat above password"%>
<div id="custom_org_id_select_menu">
<%= f.select(:skill, [['Python', 'Python'],
['Java', 'Java'],
['Rails', 'Rails'],
],
{ :multiple => true, :size => 5 }
) %>
</div>
<div id="custom_org_id hide">
<%= f.input :skill, label: "Others" %>
</div>
It does work, but if the users writes something in other
and selects something from the list (python, java etc), only what the user writes in other
is sent via the params.