ruby on rails - Activeadmin render 'new' gives Couldn't find User without an id when trying to override the create controller method -
i'm trying create page in activeadmin user can go in , create new user accounts.
i'm overriding default create method user model code below.
i'm getting error couldn't find user without id
when try render new
page.
why getting error when trying re-render new
action?
activeadmin.register user permit_params permitted = [:email, :encrypted_password] permitted << :admin if current_user.is_admin? permitted end # we're overriding new , edit controller methods create users devise. otherwise passwords don't encrypted controller 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' # causes error "couldn't find user without id" #redirect_to new_admin_user_path # redirect works fine end end end end
logs:
started "/admin/users/new" 127.0.0.1 @ 2014-03-09 21:34:35 -0500 processing admin::userscontroller#new html user load (0.4ms) select `users`.* `users` `users`.`id` = 1 order `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 "/admin/users/new" 127.0.0.1 @ 2014-03-09 21:34:42 -0500 processing admin::userscontroller#new html user load (0.2ms) select `users`.* `users` `users`.`id` = 1 order `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" 127.0.0.1 @ 2014-03-09 21:34:44 -0500 processing admin::userscontroller#create html parameters: {"utf8"=>"✓", "authenticity_token"=>"aa6tbt0laddckahs+gfokqrosvgtnxtlglwzvcovics=", "user"=>{"name"=>"", "email"=>"", "encrypted_password"=>"[filtered]", "admin"=>"0"}, "commit"=>"create user"} user load (0.6ms) select `users`.* `users` `users`.`id` = 1 order `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 id:
i'm little late game here ran this. use @user
instead of user
.
Comments
Post a Comment