Я новичок в Rails, и у меня возникают некоторые проблемы с Simple_Form, Devise и checkboxes.Rails Simple_Form Несколько флажков выбора
Я добавил несколько дополнительных столбцов в мою модель Devise, включая столбец, где я бы хотел, чтобы пользователи отмечали один или несколько флажков. Подобно этому:
Области работы: [] Англия [] Wales [] Шотландия
Все это хорошо, но когда я выбираю несколько областей, а затем сохранить, то выборы не спасают к база данных.
Вот мой Посмотреть код [приложение/просмотров/изобретают/регистрация/edit.html.erb]:
<%= simple_form_for(resource, html: { class: 'form-horizontal'}, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f| %>
<%= f.input :areas, :as => :check_boxes, :collection => ["England", "Wales", "Scotland", "Northern Ireland"] %>
<% end %>
А вот мои ApplicationController код [приложение/контроллеры /application_controller.rb]:
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
before_filter :configure_permitted_parameters, if: :devise_controller?
protected
def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) << :areas
devise_parameter_sanitizer.for(:account_update) << :areas
end
end
Я уверен, что мне не хватает чего-то очевидного, но я долгое время работал в Google.
Любая помощь была бы принята с благодарностью!
EDIT:
Извинения. Вот схема для Devise (на самом деле назвали «провайдер») таблицы:
create_table "providers", force: true 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.integer "sign_in_count", default: 0, null: false
t.datetime "current_sign_in_at"
t.datetime "last_sign_in_at"
t.string "current_sign_in_ip"
t.string "last_sign_in_ip"
t.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
t.string "last_name"
t.string "organisation"
t.string "street"
t.string "city"
t.string "county"
t.string "postcode"
t.string "areas"
t.string "methods"
end
add_index "providers", ["email"], name: "index_providers_on_email", unique: true
add_index "providers", ["reset_password_token"], name: "index_providers_on_reset_password_token", unique: true
Вы предоставили слишком мало информации. Какова ваша схема db (что означает, что области представлены в базе данных) ?. – Lucas
Является ли 'areas' ассоциацией? – kobaltz
@ Лукас - извинения. Я обновил свой вопрос, чтобы включить схему. – diferse