- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用回形针使用 heroku 将图像上传到亚马逊 S3。到目前为止,我得到:警告:无法为用户批量分配 protected 属性:图片。我已经通过了许多指南,但没有任何帮助。
我的型号:
class User < ActiveRecord::Base
resourcify
attr_accessible :login, :password, :password_confirmation, :longitue, :latitude, :showingName,:email,:contato,:telefone
has_many :api_keys
has_secure_password
has_attached_file :picture,
styles: {
thumb: '100x100>',
square: '200x200>',
medium: '300x300>',
icon: '30x30>'}#,
validates_attachment_content_type :picture, :content_type => /\Aimage\/.*\Z/
validates_attachment_file_name :picture, :matches => [/png\Z/, /jpe?g\Z/]
validates_with AttachmentSizeValidator, :attributes => :picture, :less_than => 3.megabytes
rolify :before_add => :before_add_method
def before_add_method(role)
# do something before it gets added
end
class UsersController < ApplicationController
load_and_authorize_resource
def new
end
def index
end
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'Comida was successfully created.' }
format.json { render :show, status: :created, location: @user }
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_user
@user = User.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def user_params
params.require(:user).permit(:picture,:login, :password, :longitue, :latitude, :showingName,:email,:contato,:telefone)
end
end
<%= simple_form_for @user, :html => { :class => 'form-horizontal', :multipart => true } do |f| %>
<%= f.input :nome %>
<%= f.label :picture %>
<%= f.file_field :picture %>
<%= f.input :showingName %>
<%= f.input :email %>
<%= f.input :login %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.input :contato %>
<%= f.input :telefone %>
<%= f.input :description %>
<%= f.input :laitude %>
<%= f.input :logitude %>
<div class="form-actions">
<%= f.button :submit, :class => 'btn-primary' %>
<%= link_to t('.cancel', :default => t("helpers.links.cancel")),
users_path, :class => 'btn btn-meubar' %>
</div>
<% end %>
config.paperclip_defaults = {
:storage => :s3,
:s3_host_name => 's3-sa-east-1.amazonaws.com',
:s3_credentials => {
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY'],
:bucket => ENV['S3_BUCKET_NAME']
},
:path => ":class/:id/:basename_:style.:extension",
:url => ":s3_path_url"
}
最佳答案
只需添加 :picture
至 attr_accessible
.
关于ruby-on-rails - 警告 : Can't mass-assign protected attributes Paperclip Rails 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27754553/
我正在使用带有导轨的回形针并且它工作正常,但是我的问题是更新时如果我不重新选择图像,那么它会将记录保存为 nil。这是我的代码: 'avatar', :class => 'thumb
我正在使用带有 ImageMagick 的 Paperclip 来处理几千张图像并将它们上传到 S3。它通过了数百张图像而没有出现问题,然后出现以下错误: An error was received
我已经将 rails 应用程序部署到 heroku,在我更改域之前它运行良好,在本地运行正常,现在我开始收到以下错误:Paperclip::Errors::MissingRequiredValidat
我正在使用 Paperclip 和 paperclip-ffmpeg 来处理上传。下面是我的代码 Assets 类 { :mobile => {:geometry => "400x300
我是编程新手,我正在尝试使用回形针将用户照片添加到我的用户记录中。可以从没有 行的添加新记录表单创建记录,并正确重定向并将记录保存到数据库。但是,当它包含在保存时,它想重定向到 create.htm
我刚刚在带有 rails 3.2.9 的 Ubuntu 上安装了回形针,但无法上传图像。 我得到的消息是未初始化的常量 Paperclip::Storage::Fog::Excon。 对此有什么解释吗
我在使用 mod_rails 将我的应用程序部署到运行 ubuntu 的服务器时遇到了麻烦。在服务器上运行 webrick 似乎很好,我可以保存文件,没问题。但是通过 nginx 运行应用程序,当我尝
我最近安装了回形针 gem,要将它与 Amazon S3 一起使用,我需要更改初始化程序,但我在 config/initializers 中看不到它。如何创建它?/找到它? 最佳答案 如果 paper
最近我将我的 Rails 版本从 3.2 迁移到 4.2.6,同时我修改了一些 gem,例如回形针 2.3 到 4.3.6。当我运行 rails server 时,我得到以下弃用: DEPRECATI
我正在尝试为使用 Rails 作为后端的应用程序编写一个 API,该应用程序显示膳食列表。每个餐点都显示名称和照片。对于 API,我试图返回一个 JSON 数组,其中包含与膳食模型关联的所有照片 ur
我有一些珍贵的代码可以压缩大量文件,它在 tmp 文件系统中创建了一个 zip 文件并向其中添加了文件。 我试图通过使用 ruby 的 Tempfile 将文件存储在代码中而不是自己手动将其写入
当我尝试提交表单时,出现以下错误:Validation failed: Images imageable must exist并渲染相同的 new.html.erb看法。 如果我评论 file fie
我在我的应用程序中使用 Paperclip 和 Imagemagick,使用 Amazon S3 进行存储。在开发中一切正常。但在 Heroku 的生产环境中,它无法正常工作。 图像被上传到 Amaz
我有一个带回形针的 Rails 3 应用程序。如果附件是图片,并且图片的宽度或高度小于 100,我想跳过保存。 模型中有以下内容: validate :file_dimensions, :unle
使用 Paperclip,我想从这样的 URL 抓取图像: require 'open-uri' user.photo = open(url) 问题是我最后得到一个像“open-uri20110915
我正在尝试跳过 PaperClip处理我的音乐是否已被删除。 基本上,当我上传音乐时,如果出现问题,我想销毁上传文件的每一部分。此操作由 ffmpeg 延迟并完成.另一个任务被延迟到附加图片到我的音乐
我使用回形针来调整图片的大小,如下所示: class Asset { :thumb => "80x80#", :me
我正在使用 Paperclip 通过 S3 存储图像。据我了解,Paperclip 会将一个字符串(时间戳)附加到图像的末尾以用于缓存目的。你知道他们用什么方法来创建字符串吗?我需要使用 .js 重建
我正在使用 Thoughtbot 的 Paperclip gem处理文件上传。 我发现当我上传文件名中包含空格的文件时,它会被存储为空格替换为下划线。 那挺好的。 我还尝试上传带有特殊字符的文件,例如
rails 3.0 应用程序位于使用 apache/passenger 的 ubuntu 服务器上。部署app的用户是admin,也是运行app的用户(没选名字,admin没有root权限)。我今天又
我是一名优秀的程序员,十分优秀!