かなり長い間検索していますが、解決策が見つかりませんでした。ここに私のモデルは以下のとおりです。保護された属性を一括割り当てできないため、ネストされたフォームを使用するとエラーが発生する
web.rb
class Web < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :user_type, :remember_me
belongs_to :role, :polymorphic => true
end
user.rb
class User < ActiveRecord::Base
has_one :web, :as => :role
attr_accessible :dob, :fname, :lname
end
org.rb
class Org < ActiveRecord::Base
has_one :web, :as => :role
attr_accessible :name, :website
end
すべて私は工夫/登録にsimple_form_forの代わりに、通常のform_forを使用するまで罰金だ/ new.html.erb
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :class => 'form-horizontal' }) do |f| %>
<%= f.input :email, label: false, :input_html => { :class => "span6", placeholder: "Email", type: "email", required: true}%>
<%= f.input :password, label: false, :input_html => { :class => "span6", placeholder: "Password", type: "password" }%>
<%= f.input :password_confirmation, label: false, :input_html => { :class => "span6", placeholder: "Re-enter Password", type: "password" }%>
<%= f.input :user_type, as: :hidden, :input_html => { :value => user_type} %>
<%= f.simple_fields_for resource.role do |rf| %>
<%= render :partial => "#{child_class_name.underscore}_fields", :locals => { :f => rf } %>
<% end %>
<%= f.submit "Sign up" %>
<% end %>
ネスティングの部分は、対応するフィールドが含まれている適切なmodel_fields名で部分的に置きます。
* _org_fields.html.erb *
<%= f.text_field :name, :class=>"span6", :type=>"text", :placeholder=>"Name", :required=>"" %><br />
<%= f.text_field :website, :class=>"span6", :type=>"text", :placeholder=>"Website", :required=>"" %>
問題は、私はsimple_削除する場合、すべてが正常に動作し、f.simple_fields_forです。しかし、私はそれを削除したくない。私が遭遇したエラーは、次のとおりです。
ActiveModel::MassAssignmentSecurity::Error in Devise::RegistrationsController#create
Can't mass-assign protected attributes: org
リクエストパラメータは以下のとおりです。
{"utf8"=>"✓",
"authenticity_token"=>"NnsyNdrrKJmd8QutqVs6HqZi0EnQmAmZF7zGYqnu+rI=",
"web"=>{"email"=>"",
"password"=>"[FILTERED]",
"password_confirmation"=>"[FILTERED]",
"user_type"=>"org",
"org"=>{"name"=>"",
"website"=>""}},
"commit"=>"Sign up"}
助けてください。 Web
で
使用しているレールのバージョンは? – Philip7899
@ Philip7899私はOPについて知りませんが、私はレールを使っています。3.2.13 – GeekToL