Admin :: Users中的ArgumentError #new Rails 4使用devise ruby​​ 2.0的活动admin gem

时间:2013-12-28 12:53:06

标签: ruby devise ruby-on-rails-4 activeadmin

我正在使用ruby 2.0将rails 3应用程序转换为rails 4。

devise (~> 3.2)
gem 'activeadmin', github: 'gregbell/active_admin'

我在admin中的user.rb文件如下所示

ActiveAdmin.register User do
before_filter { @skip_sidebar = true }
filter :email
filter :role, as: :check_boxes, collection: User::ROLES
filter :created_at

index do
column :email
column :role
column :created_at
column :current_sign_in_at
column :current_sign_in_ip, sortable: false
default_actions
end

show :title => :email do |ad|
attributes_table do
  row :email
  row :role
  row :created_at
  row :sign_in_count
  row :current_sign_in_at
  row :current_sign_in_ip
  row :last_sign_in_at
  row :last_sign_in_ip
end
active_admin_comments
end

form partial: 'form'

member_action :create, :method => :post do
@user = User.new(params[:user], as: :admin)
if @user.save

  redirect_to [:admin, @user]
else
  render action: "new"
end
end

member_action :update, :method => :put do
@user = User.find(params[:id])
if @user.update_attributes(params[:user], as: :admin)
  redirect_to [:admin, @user]
else
  render action: "edit"
 end
 end

end

我还创建了新用户partial来自定义视图,如下所示

- semantic_form_for [:admin, @user] do |f|
  - f.inputs do
    = f.input :email
    = f.input :role, collection: User::ROLES, include_blank: false
  - f.actions do
    = f.action :commit
    = f.action :cancel

但是我收到了以下错误

ArgumentError in Admin::Users#new

Showing /dffsdfs/app/views/admin/users/_form.html.haml where line #1 raised:

wrong number of arguments (3 for 2)

Extracted source (around line #1):

- semantic_form_for [:admin, @user] do |f|
  - f.inputs do
    = f.input :email
    = f.input :role, collection: User::ROLES, include_blank: false

2 个答案:

答案 0 :(得分:0)

当您构建表单semantic_form_for时,需要将属性作为模型,在这种情况下,admin不是模型
你需要使用这个:

- semantic_form_for @user do |f|
  - f.inputs do
    = f.input :email
    = f.input :role, collection: User::ROLES, include_blank: false

答案 1 :(得分:0)

我需要从我的gem文件中删除mete_search gem,然后才能工作。