我正在尝试在Heroku上使用Paperclip和SWS S3来让用户上传图像.
我没有将凭据存储在yml文件中.我按照Heroku页面上的说明操作:https: //devcenter.heroku.com/articles/paperclip-s3
但是,当我尝试运行我的应用程序并上传图像时,我收到此消息:
missing required :bucket option
Rails.root: /Users/scottsipiora/Sites/clycss
Application Trace | Framework Trace | Full Trace
app/controllers/instructors_controller.rb:63:in `block in update'
app/controllers/instructors_controller.rb:62:in `update'
Run Code Online (Sandbox Code Playgroud)
说明中没有提到有关在我的控制器中进行更改的任何内容.我看到一些例子告诉我要加入类似的东西:
在我的模型中,我有以下代码:
class Instructor < ActiveRecord::Base
attr_accessible :bio, :hometown, :name, :school, :sort_order, :started_sailing, :started_teaching, :photo
has_attached_file :photo, styles: {
thumb: '100x100>',
square: '200x200#',
medium: '300x300>'
}
end
Run Code Online (Sandbox Code Playgroud)
在我的production.rb中我(显然用模拟凭证替换了我的真实凭证):
config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['bucket name'],
:access_key_id => ENV['key_id'],
:secret_access_key => ENV['access_key']
}
}
Run Code Online (Sandbox Code Playgroud)
我还为Production和Dev创建了单独的存储桶,因此事情更清晰.
有任何想法吗?我比较新,这应该很容易.
提前致谢.
我正在尝试使用Rails站点map_generator gem为8,000,00页面站点生成站点地图.宝石可以在这里找到:https://github.com/kjvarga/sitemap_generator
这是我在sitemap.rb中的代码:
require 'rubygems'
require 'sitemap_generator'
# Set the host name for URL creation
SitemapGenerator::Sitemap.default_host = "http://www.mysite.com"
SitemapGenerator::Sitemap.create do
add '/content.aspx?page=privacypolicy'
Product.find_each do |product|
add product_path(ppid), :lastmod => content.updated_at
end
end
Run Code Online (Sandbox Code Playgroud)
但是,当我跑
>> ruby sitemap.rb
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
sitemap.rb:9:在`block in'中:未初始化的常量SitemapGenerator :: Interpreter :: Product(NameError)
但是"Product"是我的模型的正确名称.为什么会这样?
我正在运行Rails 3.1.2和Ruby 1.9.
我正在尝试在我的Rails 3.2应用程序中显示默认图像.我按照Carrierwave github页面上的说明进行了操作,并查看了几个Stackoverflow帖子.但是,由于某种原因,它仍然无法正常工作.
这是我的代码:
在我的photo_uploader.rb文件中,我已启用此功能:
def default_url
"/images/" + [version_name, "default.png"].compact.join('_')
end
Run Code Online (Sandbox Code Playgroud)
在我的表单和显示视图中我正在访问这样的图像:
<%= image_tag @user.photo.url %>
Run Code Online (Sandbox Code Playgroud)
我的图像的路径是:
/app/assets/images/default.png
Run Code Online (Sandbox Code Playgroud)
在我的application.rb中,我添加了以下行,因为它应该允许提供静态资产:
config.serve_static_assets = true
Run Code Online (Sandbox Code Playgroud)
但是,我的服务器在加载页面时显示以下内容:
ActionController::RoutingError (No route matches [GET] "/images/default.png")
Run Code Online (Sandbox Code Playgroud)
我也试过重新编译我的资产.
关于我做错了什么的任何想法?
我已经按照Railscast将应用程序迁移到Rails 4并转换为Strong Parameters.http://railscasts.com/episodes/415-upgrading-to-rails-4
我的创建/新方法工作正常.但是,当我尝试更新记录时,我遇到了问题.我一直收到以下消息:
CustomersController中的ArgumentError #update未知密钥:first_name
我在Stack Overflow上查看了各种帖子,还生成了一个新的Rails 4应用程序,以验证我是否正确地做事.我显然错过了一些东西.
这是更新方法的Controller代码:
def update
@customer = Customer.find(customer_params)
respond_to do |format|
if @customer.update(customer_params)
format.html { redirect_to @customer, notice: 'Customer was successfully updated.' }
format.json { head :ok }
else
format.html { render action: "edit" }
format.json { render json: @customer.errors, status: :unprocessable_entity }
end
end
end
Run Code Online (Sandbox Code Playgroud)
这是我设置强大参数的地方:
private
def set_customer
@customer = Customer.find(params[:id])
end
def customer_params
params.require(:customer).permit(:first_name, :middle_initial, :last_name, :address1, :address2, :city, :state, :zip, :phone, :gender, :email, :membership_id, :date_of_birth)
end
Run Code Online (Sandbox Code Playgroud)
非常感谢任何帮助.