我在我的应用程序和自定义用户控制器中使用设计 gem。我有链接可以在显示和索引页面中编辑用户。登录后,如果我单击 users/index.html.erb 或 users/edit.html.erb 中的编辑链接,即使发送了 GET 请求,它也会重定向到用户新表单。
在路线中,我跳过了可注册的,因为我正在使用用户控制器来处理它并且它工作正常。
这是路线
devise_for :users, :path_prefix => 'd', skip: [:registrations], controllers: {sessons: "sessions"}
resources :users
耙路线 | grep edit_user给出
edit_user_password GET /d/users/password/edit(.:format) devise/passwords#edit
edit_user GET /users/:id/edit(.:format) users#edit
用户/show.html.erb
<div class="btn btn-primary"> <%= link_to "Edit", edit_user_path(@user) %></div>
这是当我单击索引或显示页面中的编辑链接时出现的注册表单的屏幕截图。它正在发出获取请求,但显示新表单而不是编辑表单。
这是单击显示页面中的编辑链接的日志:
Started GET "/users/17/edit" for at 2013-08-19 08:40:49 +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.3ms) SELECT "users".* FROM "users" WHERE "users"."id" = 17 ORDER BY "users"."id" ASC LIMIT 1
Rendered users/_form.html.erb (17.5ms)
Rendered users/edit.html.erb within layouts/application (26.8ms)
Completed 200 OK in 50ms (Views: 47.1ms | ActiveRecord: 0.5ms
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我什至在表单中指定了 url 路径,它仍然呈现新表单
form_for(@user, :url => edit_user_path(@user))
用户/edit.html.erb
<%= render "edit" %>
用户/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 %>