我正在尝试在activeadmin中创建一个页面,用户可以进入该页面并创建新的用户帐户.
我正在使用下面的代码覆盖我的用户模型的默认创建方法.
我Couldn't find User without an ID
尝试渲染new
页面时收到错误.
尝试重新渲染new
动作时,为什么会出现此错误?
ActiveAdmin.register User do permit_params do permitted = [:email, :encrypted_password] permitted << :admin if current_user.is_admin? permitted end # We're overriding the new and edit controller methods to properly create users with devise. Otherwise the passwords don't get encrypted controller do def create user = User.new user.name = params[:user][:name] user.email = params[:user][:email] user.admin = params[:user][:admin] user.password = params[:user][:encrypted_password] user.password_confirmation = params[:user][:encrypted_password] if user.save redirect_to admin_user_path(user) else flash.now[:error] = user.errors.full_messages render 'new' # THIS CAUSES THE ERROR "Couldn't find User without an ID" #redirect_to new_admin_user_path # This redirect works just fine end end end end
日志:
Started GET "/admin/users/new" for 127.0.0.1 at 2014-03-09 21:34:35 -0500 Processing by Admin::UsersController#new as HTML User Load (0.4ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 Rendered /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@myapp/bundler/gems/active_admin-739b93bf9d22/app/views/active_admin/resource/new.html.arb (31.1ms) Completed 200 OK in 37ms (Views: 34.1ms | ActiveRecord: 0.4ms) Started GET "/admin/users/new" for 127.0.0.1 at 2014-03-09 21:34:42 -0500 Processing by Admin::UsersController#new as HTML User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 Rendered /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@myapp/bundler/gems/active_admin-739b93bf9d22/app/views/active_admin/resource/new.html.arb (32.7ms) Completed 200 OK in 60ms (Views: 35.4ms | ActiveRecord: 4.3ms) Started POST "/admin/users" for 127.0.0.1 at 2014-03-09 21:34:44 -0500 Processing by Admin::UsersController#create as HTML Parameters: {"utf8"=>"?", "authenticity_token"=>"Aa6TBt0LADDcKAHs+gFokQroSVgTnxtlgLwzvCovIcs=", "user"=>{"name"=>"", "email"=>"", "encrypted_password"=>"[FILTERED]", "admin"=>"0"}, "commit"=>"Create User"} User Load (0.6ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 ORDER BY `users`.`id` ASC LIMIT 1 (0.2ms) BEGIN (0.2ms) ROLLBACK Rendered /Users/tomcaflisch/.rvm/gems/ruby-2.1.1@myapp/bundler/gems/active_admin-739b93bf9d22/app/views/active_admin/resource/new.html.arb (14.6ms) Completed 500 Internal Server Error in 25ms ActiveRecord::RecordNotFound - Couldn't find User without an ID:
Ryan Francis.. 5
我在这里比赛有点晚了但是碰到了这个.用@user
而不是user
.
我在这里比赛有点晚了但是碰到了这个.用@user
而不是user
.