在疯狂提供的默认注册表格中,我试图添加我的几个字段:contact_no,:address,:full_name。
当Spree内部使用此Gem时,从“ spree_auth_devise”复制了完整的视图部分。
在中添加了必填表格字段 app/views/spree/shared/_user_form.html.erb
添加了所需的迁移
class AddUserRegistrationDetailsToSpreeUser < ActiveRecord::Migration
def change
add_column :spree_users, :full_name, :string
add_column :spree_users, :address, :text
add_column :spree_users, :contact_no, :integer
end
end
现在跟随模型部分:user_registration_decorator.rb
Spree::User.class_eval do
attr_accessible :email, :password, :password_confirmation,
:contact_no, :address,:full_name, :as => [:default, :user]
end
现在,通过注册表单创建新用户时,在数据库中,新添加的字段(contact_no,address,full_name)将以NULL值保存。:(
Spree 2.1.3在Rails 4上运行,并跟随Rails 4切换到strong_parameters。您可以在Rails Blog上的此博客文章中了解有关此内容的更多信息,但基本上不再使用attr_accessible,并且已在控制器中使用显式允许的参数替换了attr_accessible。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句