【发布时间】:2014-06-17 13:02:32
【问题描述】:
在尝试将我在这里和整个网络上找到的代码拼凑几个小时之后,我想我已经到了可能把我的代码弄得一团糟的地步。如果您需要任何其他 sn-ps,请告诉我,我将尝试在下面包含相关代码。用户和个人资料有不同的模型。
感谢您的帮助!
编辑:rake route 显示这条路线: admin_destroy_user 删除 /users/:id(.:format) 个人资料#destroy
我在尝试加载编辑配置文件页面 (localhost:3000/settings/profile) 时收到此错误: "没有路由匹配 {:controller=>"devise/profiles", :action=>"destroy"}"
_form.html.haml
.row
.span6
.actions
= f.submit 'Save', class: 'btn-submit'
= link_to 'Delete Account', admin_destroy_user_path, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn-delete'
= link_to 'Cancel', profile_index_path
profile_controller
def destroy
@user = User.find(params[:id])
@user.destroy
if @user.destroy
redirect_to root_url, notice: "User deleted."
end
end
routes.rb
devise_for :users
match 'users/:id' => 'devise/registrations#destroy', :via => :delete, :as => :admin_destroy_user
match 'users/:id' => 'user#show', as: :user
resources :users
ability.rb
if user.is? :admin
can :access, :admin #access the admin page
can :manage, :all #do anything to any model
else
can :read, :all #read any model
can [:update, :destroy], Profile, :user_id => user.id
【问题讨论】:
标签: ruby-on-rails ruby devise cancan