Ruby on rails Rails 4-回形针-Dropbox生产问题
我正在使用、、和Dropbox在创建产品时上载和存储图像。在本地,在开发过程中,图像文件会很好地上传到数据库中,并且是可见的,但在生产过程中,图像应该进入Dropbox,表单不会通过,我在查看Heroku日志时会遇到Dropbox身份验证错误。我已经三次检查了我的Dropbox安全密钥是否正确。我已经看过了所有相关的问题,但我找不到任何有效的方法 以下是heroku的错误:Ruby on rails Rails 4-回形针-Dropbox生产问题,ruby-on-rails,heroku,ruby-on-rails-4,paperclip,dropbox,Ruby On Rails,Heroku,Ruby On Rails 4,Paperclip,Dropbox,我正在使用、、和Dropbox在创建产品时上载和存储图像。在本地,在开发过程中,图像文件会很好地上传到数据库中,并且是可见的,但在生产过程中,图像应该进入Dropbox,表单不会通过,我在查看Heroku日志时会遇到Dropbox身份验证错误。我已经三次检查了我的Dropbox安全密钥是否正确。我已经看过了所有相关的问题,但我找不到任何有效的方法 以下是heroku的错误: DropboxAuthError (User is not authenticated.): 2014-07-12T16
DropboxAuthError (User is not authenticated.):
2014-07-12T16:04:12.514637+00:00 app[web.1]: app/controllers/products_controller.rb:31:in `block in create'
2014-07-12T16:04:12.514638+00:00 app[web.1]: app/controllers/products_controller.rb:30:in `create'
2014-07-12T16:04:12.514640+00:00 app[web.1]:
2014-07-12T16:04:12.514642+00:00 app[web.1]:
2014-07-12T16:04:12.512474+00:00 app[web.1]: Completed 500 Internal Server Error in 2361ms
这是我的产品\u控制器#创建操作:
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
@product.user = current_user
respond_to do |format|
if @product.save
format.html {
redirect_to @product,
notice: 'Product was successfully created.'
}
format.json {
render json: @product,
status: :created,
location: @product
}
else
format.html { render :new }
format.json {
render json: @product.errors,
status: :unprocessable_entity
}
end
end
end
private
def set_product
@product = Product.find(params[:id])
end
def product_params
params.require(:product).permit(:description, :name, :permalink, :price, :file, :user_id)
end
class Product < ActiveRecord::Base
if Rails.env.development?
has_attached_file :file
else
has_attached_file :file,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
belongs_to :user
has_many :sales
validates_numericality_of :price,
greater_than: 49,
message: "must be at least 50 cents"
validates_attachment_content_type :file, :content_type => %w(image/jpeg image/jpg image/png)
end
<%= form_for(@product,:html => { :multipart => true }) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :permalink %><br>
<%= f.text_field :permalink %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.number_field :price %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="field">
<%= f.label :file %><br />
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
以下是您创建的产品末尾的参数:
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
@product.user = current_user
respond_to do |format|
if @product.save
format.html {
redirect_to @product,
notice: 'Product was successfully created.'
}
format.json {
render json: @product,
status: :created,
location: @product
}
else
format.html { render :new }
format.json {
render json: @product.errors,
status: :unprocessable_entity
}
end
end
end
private
def set_product
@product = Product.find(params[:id])
end
def product_params
params.require(:product).permit(:description, :name, :permalink, :price, :file, :user_id)
end
class Product < ActiveRecord::Base
if Rails.env.development?
has_attached_file :file
else
has_attached_file :file,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
belongs_to :user
has_many :sales
validates_numericality_of :price,
greater_than: 49,
message: "must be at least 50 cents"
validates_attachment_content_type :file, :content_type => %w(image/jpeg image/jpg image/png)
end
<%= form_for(@product,:html => { :multipart => true }) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :permalink %><br>
<%= f.text_field :permalink %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.number_field :price %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="field">
<%= f.label :file %><br />
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
这是我的产品型号:
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
@product.user = current_user
respond_to do |format|
if @product.save
format.html {
redirect_to @product,
notice: 'Product was successfully created.'
}
format.json {
render json: @product,
status: :created,
location: @product
}
else
format.html { render :new }
format.json {
render json: @product.errors,
status: :unprocessable_entity
}
end
end
end
private
def set_product
@product = Product.find(params[:id])
end
def product_params
params.require(:product).permit(:description, :name, :permalink, :price, :file, :user_id)
end
class Product < ActiveRecord::Base
if Rails.env.development?
has_attached_file :file
else
has_attached_file :file,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
belongs_to :user
has_many :sales
validates_numericality_of :price,
greater_than: 49,
message: "must be at least 50 cents"
validates_attachment_content_type :file, :content_type => %w(image/jpeg image/jpg image/png)
end
<%= form_for(@product,:html => { :multipart => true }) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :permalink %><br>
<%= f.text_field :permalink %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.number_field :price %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="field">
<%= f.label :file %><br />
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
类产品:dropbox,
:dropbox_credentials=>Rails.root.join(“config/dropbox.yml”),
:path=>“:style/:id\uu:filename”
结束
属于:用户
有很多:销售
验证:价格的数值性,
大于:49,
信息:“必须至少50美分”
验证附件内容类型:文件,:内容类型=>%w(image/jpeg-image/jpg-image/png)
结束
最后是创建新产品的表单:
# POST /products
# POST /products.json
def create
@product = Product.new(product_params)
@product.user = current_user
respond_to do |format|
if @product.save
format.html {
redirect_to @product,
notice: 'Product was successfully created.'
}
format.json {
render json: @product,
status: :created,
location: @product
}
else
format.html { render :new }
format.json {
render json: @product.errors,
status: :unprocessable_entity
}
end
end
end
private
def set_product
@product = Product.find(params[:id])
end
def product_params
params.require(:product).permit(:description, :name, :permalink, :price, :file, :user_id)
end
class Product < ActiveRecord::Base
if Rails.env.development?
has_attached_file :file
else
has_attached_file :file,
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
end
belongs_to :user
has_many :sales
validates_numericality_of :price,
greater_than: 49,
message: "must be at least 50 cents"
validates_attachment_content_type :file, :content_type => %w(image/jpeg image/jpg image/png)
end
<%= form_for(@product,:html => { :multipart => true }) do |f| %>
<% if @product.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@product.errors.count, "error") %> prohibited this product from being saved:</h2>
<ul>
<% @product.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br>
<%= f.text_field :name %>
</div>
<div class="field">
<%= f.label :permalink %><br>
<%= f.text_field :permalink %>
</div>
<div class="field">
<%= f.label :description %><br>
<%= f.text_area :description %>
</div>
<div class="field">
<%= f.label :price %><br>
<%= f.number_field :price %>
</div>
<div class="field">
<%= f.label :user_id %><br>
<%= f.text_field :user_id %>
</div>
<div class="field">
<%= f.label :file %><br />
<%= f.file_field :file %>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
{:multipart=>true})do | f |%>
禁止保存此产品:
使用此方法时,不要忘记告诉Heroku有关费加罗宝石的重要步骤
rake figaro:heroku
他为我做了这件事。查看,我没有看到该命令,但有一节专门介绍如何部署到Heroku。我遇到了一个类似的问题,最后不得不将环境从开发更改为生产
class Listing < ActiveRecord::Base
if Rails.env.production?
has_attached_file :image,
:styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg",
:storage => :dropbox,
:dropbox_credentials => Rails.root.join("config/dropbox.yml"),
:path => ":style/:id_:filename"
validates_attachment_content_type :image, :content_type => %w(image/jpeg image/jpg image/png)
else
has_attached_file :image,
:styles => { :medium => "200x", :thumb => "100x100>" }, :default_url => "default.jpg"
end
end
类列表{:medium=>“200x”,:thumb=>“100x100>”},:default_url=>“default.jpg”,
:存储=>:dropbox,
:dropbox_credentials=>Rails.root.join(“config/dropbox.yml”),
:path=>“:style/:id\uu:filename”
验证附件内容类型:image,:content\u type=>%w(image/jpeg-image/jpg-image/png)
其他的
已附加文件:图像,
:style=>{:medium=>“200x”,:thumb=>“100x100>”},:default_url=>“default.jpg”
结束
结束
我不知道为什么当指定开发而不是生产时它不起作用,但至少后者起作用。我可能会晚些回答,但它可能会帮助别人 在Dropbox的开发者控制台中,更改
'Development user'
设置是有效的。
最初创建应用程序时,“开发用户”
将是“仅限您”
因此,单击“启用其他用户”按钮,允许更多用户访问该应用程序