默认情况下,我的模型关联显示在 rails_admin 的“添加新”选项卡中。但是,如果我修改 rails_admin.rb 文件并使用 config.model 自定义视图中出现的字段,它显然会将其从视图中删除。
在我的示例中,我有一个客户和一个用户。
用户.rb
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :role, :company, :customer_id
belongs_to :customer
end
客户.rb
class Customer < ActiveRecord::Base
attr_accessible :city, :name, :state, :street, :zip, :container_id, :user_id
has_many :users
end
所以现在如果我登录到 rails_admin 仪表板并去添加一个新用户,我有一个下拉选项来选择一个客户,一个按钮来添加一个新客户,一个按钮来编辑一个客户。但是,一旦我在 rails_admin.rb 中添加了我的 config.model。
rails_admin.rb
config.model 'User' do
list do
field :name do
label "Name"
end
field :email do
label "Email"
end
field :company do
label "Company"
end
field :role do
label "Role"
end
end
edit do
field :name do
label "Name"
end
field :email do
label "Email"
end
field :company do
label "Company"
end
field :role do
label "Role"
end
field :role, :enum do
enum do
['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5']
end
label "Role"
end
end
create do
field :name do
label "Name"
end
field :email do
label "Email"
help "The email address will serve as the username."
end
field :password do
label "Password"
end
field :password_confirmation do
label "Password Confirmation"
help "Required"
end
field :company do
label "Company"
end
field :role, :enum do
enum do
['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5']
end
label "Role"
end
end
end
当我想添加用户时,这将覆盖我拥有的关联字段。我的问题是我应该在 rails_admin 中使用什么语法来明确告诉 rails_admin 配置,当我在 rails_admin 中添加用户时,我希望显示模型关联。
谢谢!