古いRailsアプリを継承しましたが、このエラーに本当に苦労しています:
ActionController::RoutingError
(No route matches {:controller=>"users", :action=>"profile"}):
app/views/layouts/application.html.erb:59:in
`_app_views_layouts_application_html_erb__105<snip>'
app/controllers/users_controller.rb:40:in `index'
このエラーは、他のユーザーとしてではなく、管理者としてログインした場合にのみ発生します。
ここに私のroutes.rbがあります
Vvault::Application.routes.draw do
resources :orders
devise_for :users
resources :videos
resources :users
root :to => "users#index"
match 'users/:id/profile' => 'users#profile', :as => :user_profile
end
これは users_controller.rb からの関連するスニペットだと思います:
def index
if current_user.admin?
# admin sees all users
@users = User.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @users }
end
else
redirect_to "/users/" + current_user.id.to_s() and return
end
end
これは、application_html.erb からの関連するスニペットだと思います。
<div class="sidebar">
<% if user_signed_in? %>
<%= link_to "My account", user_profile_path, :method => :get %>
<% end %>
</div>
application_html.erb の 3 行目をコメント アウトすると、管理者としてログインできますが、明らかに、どのユーザーに対してもプロファイル リンクが表示されません。
どんな助けでも感謝します。
ありがとう!