我有一个应用程序在本地运行时在尝试上传个人资料图片时吐出以下错误。我安装了ImageMagick。我试图卸载并重新安装,但这并没有解决问题。在routes.rb中我应该注意什么?有问题的地方下一步...如果有更好的方法来处理个人资料图片,欢迎提出建议:
ActionController::RoutingError (No route matches [GET] "/users"):
actionpack (4.2.4) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
railties (4.2.4) lib/rails/rack/logger.rb:38:in `call_app'
railties (4.2.4) lib/rails/rack/logger.rb:22:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/request_id.rb:21:in `call'
rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
rack (1.6.4) lib/rack/runtime.rb:18:in `call'
activesupport (4.2.4) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
rack (1.6.4) lib/rack/lock.rb:17:in `call'
actionpack (4.2.4) lib/action_dispatch/middleware/static.rb:116:in `call'
rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
railties (4.2.4) lib/rails/engine.rb:518:in `call'
railties (4.2.4) lib/rails/application.rb:165:in `call'
rack (1.6.4) lib/rack/content_length.rb:15:in `call'
puma (2.14.0) lib/puma/server.rb:541:in `handle_request'
puma (2.14.0) lib/puma/server.rb:388:in `process_client'
puma (2.14.0) lib/puma/server.rb:270:in `block in run'
puma (2.14.0) lib/puma/thread_pool.rb:106:in `block in spawn_thread'
routes.rb(引用用户):
namespace :api do
namespace :v1 do
resources :users, only: [:create, :update, :delete, :show]
post 'users/login', to: 'users#login', as: :login
get 'users/:user_id/place/:requesting_user_id', to: 'userfeed#show'
get 'users/:user_id/feed', to: 'feed#show' # all my friends feed
post 'users/:user_id/follow', to: 'friend#follow'
post 'users/:user_id/unfollow', to: 'friend#unfollow'
...
答案 0 :(得分:2)
您已将users
的路由配置为仅包含:create
,:update
,:delete
,:show
。如果您添加:index
,则错误应该消失。
resources :users, only: [:index, :create, :update, :delete, :show]
当然,这意味着您需要在控制器上执行索引操作。
例如,在users_controller.rb中,您可以添加:
def index
@users = User.all
end
但是,我怀疑您可以配置用于保存图像的方法以重定向到用户个人资料视图而不是用户列表视图,以避免添加此新操作。