ピンによって生成されたパスを変更して、管理者ユーザーが別のユーザーのピンにアクセスし、それらを削除できるようにしたいと考えています。
devise でユーザー モデルを作成し、admin 属性を追加しました。これは正常に機能しますが、コントローラーで各ピンを current_user に関連付けているため、管理者ユーザーとしてログインしている間、他のピンを削除したり、ピンを表示したりすることはできません。
問題はpins_controller.rbにあると思います
@pin = current_user.pins.find(params[:id])
以下は、機能していない実際のルートです
<% if current_user == pin.user or user_signed_in? && current_user.admin? %>
<p>
<%= link_to content_tag(:i, "", class:"icon-edit"), edit_pin_path(pin) %> |
<%= link_to content_tag(:i, "", class:"icon-trash"), pin, method: :delete, data: { confirm: 'Are you sure?' } %>
</p>
<% end %>
また、これについては間違っている可能性があり、問題はroutes.rbファイルにある可能性があります
Omrails::Application.routes.draw do
get "users/show"
resources :pins
devise_for :users
match 'users/:id' => 'users#show', as: :user
get 'about' => 'pages#about'
root :to => 'pins#index'
私の git リポジトリはここにあります: https://github.com/nathan-wallace/imageapp.git