rails-4 devise + user controller edit route redirecting to the wrong place
I am using devise gem in my app and a custom user controller. I have links
to edit a user in the show and index page. After signing in, if I click
the edit link in users/index.html.erb, it redirects to user registration
form and when I click thesame link from the show.index.erb, it throws
Routing Error No route matches [POST] "/users/17/edit". In the route, I am
skipping registrable because I am using the User controller to handle that
and it works fine.
this is the route
devise_for :users, :path_prefix => 'd', skip: [:registrations],
controllers: {sessons: "sessions"}
resources :users
The users_controller.rb
class UsersController < ApplicationController
before_action :set_user, only: [:show, :edit, :update, :destroy]
before_filter :authenticate_user!, except: [:new, :create]
respond_to :html, :json
def show
end
def edit
end
private
def set_user
@user = User.find(params[:id])
end
end
users/edit.html.erb
<%= render "form" %>
users/index.html.erb
<% @users.each do |user| %>
<div class="btn btn-primary"><%= link_to "Edit", edit_user_path(user) %>
</div>
<div class="btn btn-danger"><%= link_to 'Remove', user, method: :delete,
data: {confirmation: 'Are you sure'} %></div>
<% end %>
users/show.html.erb
<div class="btn btn-primary"> <%= button_to "Edit", edit_user_path(@user)
%></div>
If I click the link above, I get Routing Error No route matches [POST]
"/users/17/edit" This is image of the error:
This is the image of the registration form that comes up when I click on
the edit link in the index form. A different image from what I get when I
click the edit link but from the show page as shown in the first image.
The stack trace from clicking the edit link in the show page:
Started POST "/users/17/edit" at 2013-08-18 19:43:40 +0000
ActionController::RoutingError (No route matches [POST] "/users/17/edit"):
actionpack (4.0.0)
lib/action_dispatch/middleware/debug_exceptions.rb:21:in call'
actionpack (4.0.0)
lib/action_dispatch/middleware/show_exceptions.rb:30:incall'
railties (4.0.0) lib/rails/rack/logger.rb:38:in call_app'
railties (4.0.0) lib/rails/rack/logger.rb:21:inblock in call'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in block in
tagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:25:intagged'
activesupport (4.0.0) lib/active_support/tagged_logging.rb:67:in tagged'
railties (4.0.0) lib/rails/rack/logger.rb:21:incall'
actionpack (4.0.0) lib/action_dispatch/middleware/request_id.rb:21:in call'
rack (1.5.2) lib/rack/methodoverride.rb:21:incall'
rack (1.5.2) lib/rack/runtime.rb:17:in call'
activesupport (4.0.0)
lib/active_support/cache/strategy/local_cache.rb:83:incall'
rack (1.5.2) lib/rack/lock.rb:17:in call'
actionpack (4.0.0) lib/action_dispatch/middleware/static.rb:64:incall'
railties (4.0.0) lib/rails/engine.rb:511:in call' rack (1.5.2)
lib/rack/lock.rb:17:incall'
rack (1.5.2) lib/rack/content_length.rb:14:in call'
rack (1.5.2) lib/rack/handler/webrick.rb:60:inservice'
/home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:138:in
service'
/home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/httpserver.rb:94:inrun'
/home/action/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/webrick/server.rb:295:in
`block in start_thread'
Rendered
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/_trace.erb
(1.2ms)
Rendered
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/routes/_route.html.erb
(3.7ms)
Rendered
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/routes/_table.html.erb
(4.3ms)
Rendered
/home/action/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-4.0.0/lib/action_dispatch/middleware/templates/rescues/routing_error.erb
within rescues/layout (77.1ms)
**Stack trace from clicking the edit button from the index page**
Started GET "/users/17/edit" for undefined at 2013-08-18 19:46:02 +0000
Processing by UsersController#edit as HTML
Parameters: {"id"=>"17"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ?
LIMIT 1 [["id", "17"]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 17
ORDER BY "users"."id" ASC LIMIT 1
Rendered users/_form.html.erb (57.7ms)
Rendered users/edit.html.erb within layouts/application (59.0ms)
Completed 200 OK in 80ms (Views: 77.4ms | ActiveRecord: 0.4ms)
Started GET "/users/17/edit" at 2013-08-18 19:46:02 +0000
Processing by UsersController#edit as HTML
Parameters: {"id"=>"17"}
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = ?
LIMIT 1 [["id", "17"]]
User Load (0.2ms) SELECT "users".* FROM "users" WHERE "users"."id" = 17
ORDER BY "users"."id" ASC LIMIT 1
Rendered users/_form.html.erb (2.5ms)
Rendered users/edit.html.erb within layouts/application (3.3ms)
Completed 200 OK in 23ms (Views: 20.0ms | ActiveRecord: 0.5ms)
No comments:
Post a Comment