0

我不确定最好的方法是什么,但在某种程度上我有点混淆了自己。我想要做的是管理员进入用户个人资料并修改项目的一种方式。

路线

  devise_for :customers, :controllers => {:registrations => 'registrations'}
  resources :usermanagements

控制器

class RegistrationsController < Devise::RegistrationsController
  def update
    # required for settings form to submit when password is left blank
    @customer = Customer.find(current_customer.id)
    if @customer.update_attributes(params[:customer])
      set_flash_message :notice, :updated
      # Sign in the customer bypassing validation in case his password changed
      sign_in @customer, :bypass => true
      redirect_to after_update_path_for(@customer)
    else
      render "edit"
    end
  end

  def edit
   @customer = current_customer
  end
end

控制器

class UsermanagementsController < ApplicationController
  def index
    @usermngmts = Customer.paginate(:page => params[:page], :per_page => 30)
  end
  def show
    @usermngmts = Customer.find(params[:id])
  end
end

查看registration/edit.html.erb

# i am trying to designate this one for public view
<%= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put })  do |f| %>
...
<% end %>

这有效

查看 usermanagements/index.html.erb

<% @usermngmts.each do |usrmngmt| %>
    <%= usrmngmt.incomplete_name %>
    <%= link_to ... i would like to go to the edit of usermanagement controller but get usermngents/userid/edit %>
    </div>
<% end%>

不混合这两个控制器的最佳方法是什么

4

1 回答 1

1

我不太清楚你要做什么,但如果你想为管理员提供一个单独的控制器来管理注册(或客户),你总是可以创建一个“管理员”命名空间,然后使用 admin/registrations 和 admin/customers 控制器提供自定义的路由和操作,访问权限仅限于管理员。

此处有关命名空间的更多信息:http: //guides.rubyonrails.org/routing.html#controller-namespaces-and-routing

于 2013-01-16T03:05:34.473 回答