问题描述:

I read all the thread on this, but I still can't figure out what is wrong. I have gone through all the devise implementation guides and followed them but after a new user registration, the redirect goes to the users controller, specifically users#show.

The initial call to a new registration is going through my registrations controller. That has been verified. But after the registration it doesn't pass through the registrations controller again. It goes through the users controller. I put a break in the two overriding methods in the new registrations controller and they never hit.

/routes.rb

Rails.application.routes.draw do

root to: 'app#index'

devise_for :users, controllers: { registrations: "registrations" }

resources :users do

member do

put 'follow', to: 'users#follow'

put 'unfollow', to: 'users#unfollow'

end

end

end

registrations_controller.rb

class RegistrationsController < Devise::RegistrationsController

protected

#call for new registration does pass through here

#after new registration does not pass through here

def after_inactive_sign_up_path_for(resource)

#never gets here after new registration

other_path(resource)

end

def after_sign_up_path_for(resource)

#never gets here after new registration

other_path(resource)

end

end

new registration form:

 <form action="index.html">

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>

<%= devise_error_messages! %>

<div class="form-group">

<%= f.email_field :email, autofocus: true, placeholder: "Email", class: "form-control rounded input-lg text-center no-border" %>

</div>

<div class="form-group">

<% if @minimum_password_length %>

<em>(<%= @minimum_password_length %> characters minimum)</em>

<% end %><br />

<%= f.password_field :password, autocomplete: "off", placeholder: "Password", class: "form-control rounded input-lg text-center no-border" %>

</div>

<div class="form-group">

<%= f.password_field :password_confirmation, autocomplete: "off", placeholder: "Confirm Password", class: "form-control rounded input-lg text-center no-border" %>

</div>

<div class="checkbox i-checks m-b">

<label class="m-l">

<input type="checkbox" checked=""><i></i> Agree the <a href="#">terms and policy</a>

</label>

</div>

<button type="submit" class="btn btn-lg btn-warning lt b-white b-2x btn-block btn-rounded"><i class="icon-arrow-right pull-right"></i><span class="m-r-n-lg">Sign up</span></button>

<% end %>

<div class="text-center m-t m-b"><small><%= link_to "Already have an account?", new_session_path(resource_name) %></small></div>

console:

Started GET "/users/index.html?utf8=%E2%9C%93&authenticity_token=KlAk4ctYpw%2F2eHGqZ0OsAymf5BxUPxeBiFzeOatn2JDUQJdPk8fGoB%2BmuN4oeN3KviQdVwN%2FxMfnjH4zIVooOg%3D%3D&user%5Bemail%5D=asdf%40asdf.com&user

%5Bpassword%5D=[FILTERED]&user%5Bpassword_confirmation%5D=[FILTERED]" for ::1 at 2016-10-25 22:10:37 -0400

Processing by UsersController#show as HTML

Parameters: {"utf8"=>"✓", "authenticity_token"=>"KlAk4ctYpw/2eHGqZ0OsAymf5BxUPxeBiFzeOatn2JDUQJdPk8fGoB+muN4oeN3KviQdVwN/xMfnjH4zIVooOg==", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]

", "password_confirmation"=>"[FILTERED]"}, "id"=>"index"}

User Load (0.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 0], ["LIMIT", 1]]

Completed 404 Not Found in 3ms (ActiveRecord: 0.3ms)

ActiveRecord::RecordNotFound (Couldn't find User with 'id'=index):

app/controllers/users_controller.rb:6:in `show'

Rendering /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout

Rendering /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb

Rendered /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_source.html.erb (3.7ms)

Rendering /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb

Rendered /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (1.8ms)

Rendering /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb

Rendered /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.0ms)

Rendered /Users/Joe/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/actionpack-5.0.0.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (69.3ms)

request params:

{"utf8"=>"✓",

"authenticity_token"=>"KlAk4ctYpw/2eHGqZ0OsAymf5BxUPxeBiFzeOatn2JDUQJdPk8fGoB+muN4oeN3KviQdVwN/xMfnjH4zIVooOg==",

"user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"},

"id"=>"index",

"format"=>"html"}

网友答案:

If you want to go to users#show, the correct path helper should be user_path(resource), is it what you want?

网友答案:

It looks like the issue is two-fold. The registrations controller is looking for the incorrect path but it also needs a proper id. I think the solution here is to pass it user_path(@user.id) instead of having resource as an argument where you have it in new_user_path(resource).

It's attempting to query for a User that has an ID of "Index" which doesn't exist and therefore it's throwing an error. You'll want to find the id of your new user and insert that to the route so that it finds that specific User profile. I used @user as an example. You can define that variable in the code or work with whatever variable you wish. I hope that helps!

相关阅读:
Top