2011-11-14 94 views
1

我剛將活動管理員添加到我的導軌應用程序,我無法創建新用戶。我正在使用活動管理員創建的用戶模型,並添加了一些添加的列,如名和姓。當我爲新用戶填寫表單並單擊創建新用戶時,該頁面將刷新,但不會保存我的用戶,也不會進入包含成功消息的回顧頁面。無法使用ActiveAdmin創建新用戶

這裏是我的ADMINUSER模型

class AdminUser < ActiveRecord::Base 
    devise :database_authenticatable, 
    :recoverable, :rememberable, :trackable, :validatable 

    attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name 

end 

這裏是我的主動管理類

ActiveAdmin.register AdminUser do 
    index do 
    column :first_name 
    column :last_name 
    column :email 

    default_actions 
    end 

form do |f| 
    f.inputs "User Details" do 
    f.inputs :email 
    f.inputs :first_name 
    f.inputs :last_name 
    end 
    f.buttons 
end 
end 

回答

3

忘了這個小傢伙添加到模型...... FML

after_create { |admin| admin.send_reset_password_instructions } 

def password_required? 
    new_record? ? false : super 
end 
2

這是在當你的環境中指定config.cache_classes = false表現Rails的重裝錯誤代碼做。

config/environments/development.rb中將其更改爲true,重新啓動服務器,並且您應該能夠創建用戶。

但是這並不理想,和一個解決辦法suggested here是把你的config/environments/development.rb如下:

config.to_prepare do 
    Thread.current.keys.each{ |k| Thread.current[k] = nil if k.to_s =~ /_scoped_methods$/ } 
    end 

雖然這個bug似乎解決了,我看到了問題3.1.1其中上面的代碼修復。

即使這是Rails中的一個bug,如果您想了解更多關於此的討論,它也會記錄爲bug in active_admin

7

我的解決辦法:

ActiveAdmin.register User do 
    permit_params [:email, :password, :password_confirmation] 

    form do |f| 
     f.inputs "User" do 
     f.input :email 
     f.input :password 
     f.input :password_confirmation 
     end 
     f.actions 
    end 
end 
0

Upvoting @ Danpe的答案。 「密碼」是必填字段。所以你需要把它添加到permit_params中,並在表單中要求輸入密碼。只有這樣才能正確保存表單。這裏是我的許可PARAMS字符串,也修正了創建ActiveAdmin用戶這裏提到的其他問題:https://github.com/gregbell/active_admin/issues/2595

controller do 
    def permitted_params 
     params.permit :utf8, :_method, :authenticity_token, :commit, :id, 
       model: [:attribute1, :attribute2, etc] 
    end 
end 
+0

那仁我遵循了這一解決方案,它解決了未經許可的問題,但但是我不知道爲什麼它不這樣做的更新行動。我嘗試更新記錄,但在修補程序操作後,它會回滾。你有什麼想法,爲什麼? http://stackoverflow.com/questions/24971627/activeadmin-after-create-redirecting-to-show-update-actions-error – BC2