我正在编写一个学习Rails开发的教程。
如果这个问题多余,我道歉。可能是我的初学经验水平使得难以找到相关的现有答案。
真正感谢任何帮助。
本课程的目的是构建一个类似Reddit的站点。在本课中,我应该使用带有CarrierWave和MiniMagick宝石的S3存储来实现图像上传。据我所知,我已经密切关注了课程的说明,但也许我错过了一些东西。
当我尝试从编辑视图上传图像文件时,会发生这种情况。
这是错误:
app/controllers/users_controller.rb:5:in `update'
Rendered /Users/gregorybowler/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (8.5ms)
Rendered /Users/gregorybowler/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (3.5ms)
Rendered /Users/gregorybowler/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (2.4ms)
Rendered /Users/gregorybowler/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (64.7ms)
Cannot render console with content type multipart/form-dataAllowed content types: [#<Mime::Type:0x007fd34a40cb10 @synonyms=["application/xhtml+xml"], @symbol=:html, @string="text/html">, #<Mime::Type:0x007fd34a40ce30 @synonyms=[], @symbol=:text, @string="text/plain">, #<Mime::Type:0x007fd3493e8d88 @synonyms=[], @symbol=:url_encoded_form, @string="application/x-www-form-urlencoded">]
Started PATCH "/users/8" for ::1 at 2015-07-03 22:05:20 -0700
ActionController::RoutingError (uninitialized constant UsersController):
activesupport (4.2.1) lib/active_support/inflector/methods.rb:261:in `const_get'
activesupport (4.2.1) lib/active_support/inflector/methods.rb:261:in `block in constantize'
activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in `each'
activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in `inject'
activesupport (4.2.1) lib/active_support/inflector/methods.rb:259:in `constantize'
这是我的user_controller.rb文件:
class UsersController < ApplicationController
before_action :authenticate_user!
def update
if current_user.update_attributes(user_params)
flash[:notice] = "User information updated"
redirect_to edit_user_registration_path
else
flash[:error] = "Invalid user information"
redirect_to edit_user_registration_path
end
end
private
def user_params
params.require(:user).permit(:name, :avatar)
end
end
这是config / routes.rb
Rails.application.routes.draw do
devise_for :users
resources :users, only: [:update]
resources :topics do
resources :posts, except: [:index]
end
get 'about' => 'welcome#about'
root to: 'welcome#index'
end
答案 0 :(得分:3)
UsersController
常数,这是您的类。
你说这是user_controller.rb
。但是,Rails自动加载只能找到UsersController
,注意's',你猜对了,app/controllers/users_controller.rb
。 (很难记住,惯例规定#{thing}Controller
是复数)