我是Rails的新手,我在Simple_Form,Devise和复选框方面遇到了一些问题。
我在我的Devise模型中添加了一些额外的列,包括我希望用户勾选一个或多个复选框的列。与此类似:
行动区域:[]英格兰[]威尔士[]苏格兰
一切都很好,但是当我选择多个区域,然后保存时,选择不会保存到数据库中。
这是我的查看代码 [app / views / devise / registrations / 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代码 [app / controllers / 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
我确信我错过了一些明显的东西,但我一直在谷歌上搜索几个小时而没有运气。
非常感谢任何帮助!
编辑:
道歉。这是Devise(实际上命名为'providers')表的方案:
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