我不确定什么是最好的方法,但在某种程度上,我有点把自己搞混了。我想做的是一个管理员进入用户配置文件和修改项目的方式。
路线 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
视图注册/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%>
不把这两个控制器混在一起的最好方法是什么
我不太清楚你想做什么,但是如果你想为管理员提供一个单独的控制器来管理注册(或客户),你总是可以创建一个"admin"命名空间,然后使用admin/registrations和admin/customers控制器来提供定制的路由和操作,访问仅限于管理员。
更多关于名称空间的信息:http://guides.rubyonrails.org/routing.html#controller-namespaces-and-routing