Rails错误 - 无法加载此类文件 - aws-sdk(您可能需要安装aws-sdk gem)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Rails错误 - 无法加载此类文件 - aws-sdk(您可能需要安装aws-sdk gem)相关的知识,希望对你有一定的参考价值。
我有一个RoR应用程序,通过回形针和亚马逊s3上传图像。在我决定将路线从myapp.com/id更改为myapp.com/model-name之前,一切正常。现在我收到以下错误:LoadError cannot load such file -- aws-sdk (You may need to install the aws-sdk gem)
。这些更改涉及更改模型,控制器和数据库。
模型:
class Major < ActiveRecord::Base
attr_accessible :glance, :name, :image
# Validations
validates :glance, presence: true
validates :name, presence: true
validates_attachment :image, content_type: {content_type: ['image/jpeg', 'image/jpg', 'image/png', 'image/gif']}, size: { less_than: 5.megabytes }
validates :slug, uniqueness: true, presence: true
before_validation :generate_slug
# Associations
has_attached_file :image, styles: {
profile: "350x350>",
similar: '166x134>',
thumb: "100x100>"
},
:storage => :s3,
:bucket => 'major finder'
:s3_credentials => {
:access_key_id => 'my_key_id',
:secret_access_key => 'my_secret_access_key'
},
:path => "/majors/:attachment/:style/:filename"
# make the url path memorable (instead of using the id)
def to_param
slug
end
def generate_slug
self.slug ||= name.parameterize
end
end
控制器:
class MajorsController < ApplicationController
before_filter :authenticate_user!, only: [:new, :edit]
before_filter :find_page, only: [:show, :edit, :update, :destroy]
def index
@majors_recent = Major.order("created_at DESC")
@majors = Major.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @majors }
end
end
def show
respond_to do |format|
format.html # show.html.erb
format.json { render json: @major }
end
end
def new
@major = Major.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @major }
end
end
def edit
end
def create
@major = Major.new(params[:major])
respond_to do |format|
if @major.save
format.html { redirect_to @major, notice: 'Major was successfully created.' }
format.json { render json: @major, status: :created, location: @major }
else
format.html { render action: "new" }
format.json { render json: @major.errors, status: :unprocessable_entity }
end
end
end
def update
respond_to do |format|
if @major.update_attributes(params[:major])
format.html { redirect_to @major, notice: 'Major was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @major.errors, status: :unprocessable_entity }
end
end
end
def destroy
@major.destroy
respond_to do |format|
format.html { redirect_to majors_url }
format.json { head :no_content }
end
end
private
def find_page
@major = Major.find_by_slug!(params[:id])
end
end
我的数据库架构如下所示:
create_table "majors", :force => true do |t|
t.text "glance", :limit => 255
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.string "name"
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
end
这是我的Gemfile:
gem 'rails', '3.2.11'
gem 'jquery-rails'
gem 'devise'
gem 'simple_form'
gem 'aws-sdk'
gem "paperclip", "~> 3.0"
gem 'sunspot_rails'
gem 'activeadmin'
group :production do
gem 'pg'
end
group :development, :test do
gem 'sqlite3'
gem 'sunspot_solr'
end
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass', '~> 2.2.2.0'
end
我跑$ rails g migration add_slug_to_majors slug:index
然后$ rake db:migrate
现在即使我删除了所有的更改我仍然得到这个错误。我看了一遍,找不到解决方案。有没有人有任何想法?
该解决方案是错误编写的,您在开发模式中也需要aws-sdk
gem(因为您在模型中使用它)。只需将gem 'aws-sdk'
移到小组外。
顺便说一句:在开发和生产模式下使用相同的数据库引擎,我对你的配置有一些问题。
这实际上是您在Gemfile中管理版本时可能遇到的问题。
在我的情况下,它是一个较新版本的回形针导致问题。降级到旧版本为我修复了它。
以上是关于Rails错误 - 无法加载此类文件 - aws-sdk(您可能需要安装aws-sdk gem)的主要内容,如果未能解决你的问题,请参考以下文章
rails 无法加载此类文件 -- rake (LoadError)
错误无法加载此类文件 -- user_agent/browsers/playstation (LoadError)