我尝试编写一个图像验证格式,确保url以.png,.jpg或.gif结尾.
class Product < ActiveRecord::Base
mount_uploader :image_url
validates :title, :presence => true,
:uniqueness => true
validates :image_url, :presence => true,
:format => {
:with => %r{\.(gif|jpg|png)$}i,
:message => 'must be a URL for GIF, JPG or PNG image.'
}
end
Run Code Online (Sandbox Code Playgroud)
但是,当我启动我的服务器.看到这个:
提供的正则表达式使用多行锚点(^或$),这可能会带来安全风险.你的意思是使用\ A和\ z,还是忘了添加:multiline => true选项?
在我的ruby on rails项目中,我使用capistrano,unicorn,postgresql和nginx来部署我的项目.当我运行时,cap production git:check 我收到此错误:
Error reading response length from authentication socket.
Run Code Online (Sandbox Code Playgroud)
日志跟踪:
INFO [13522bc0] Running /usr/bin/env mkdir -p /tmp/deploy_test/ as mezbah@192.168.137.130
DEBUG [13522bc0] Command: /usr/bin/env mkdir -p /tmp/deploy_test/
INFO [13522bc0] Finished in 0.291 seconds with exit status 0 (successful).
DEBUG Uploading /tmp/deploy_test/git-ssh.sh 0.0%
INFO Uploading /tmp/deploy_test/git-ssh.sh 100.0%
INFO [3b379ef0] Running /usr/bin/env chmod +x /tmp/deploy_test/git-ssh.sh as mezbah@192.168.137.130
DEBUG [3b379ef0] Command: /usr/bin/env chmod +x /tmp/deploy_test/git-ssh.sh
INFO [3b379ef0] Finished in 0.067 seconds with exit status 0 (successful).
INFO [8355617a] Running …Run Code Online (Sandbox Code Playgroud) 找不到文件'jquery.ui.datepicker'(在C:/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/bundler/gems/active_admin-f65e7cd6425b/app/assets/javascripts/active_admin/base .js.coffee:2)
认为gem'sprockets'的问题
sprockets (2.11.0) lib/sprockets/context.rb:106:in `resolve'
sprockets (2.11.0) lib/sprockets/context.rb:146:in `require_asset'
sprockets (2.11.0) lib/sprockets/directive_processor.rb:217:in `process_require_directive'
sprockets (2.11.0) lib/sprockets/directive_processor.rb:167:in `block in process_directives'
sprockets (2.11.0) lib/sprockets/directive_processor.rb:165:in `each'
sprockets (2.11.0) lib/sprockets/directive_processor.rb:165:in `process_directives'
sprockets (2.11.0) lib/sprockets/directive_processor.rb:99:in `evaluate'
tilt (1.4.1) lib/tilt/template.rb:103:in `render'
sprockets (2.11.0) lib/sprockets/context.rb:197:in `block in evaluate'
sprockets (2.11.0) lib/sprockets/context.rb:194:in `each'
sprockets (2.11.0) lib/sprockets/context.rb:194:in `evaluate'
sprockets (2.11.0) lib/sprockets/processed_asset.rb:12:in `initialize'
sprockets (2.11.0) lib/sprockets/base.rb:374:in `new'
sprockets (2.11.0) lib/sprockets/base.rb:374:in `block in build_asset'
sprockets (2.11.0) lib/sprockets/base.rb:395:in `circular_call_protection'
sprockets (2.11.0) lib/sprockets/base.rb:373:in `build_asset'
sprockets (2.11.0) lib/sprockets/index.rb:94:in `block in build_asset'
sprockets …Run Code Online (Sandbox Code Playgroud) 查看 rails guide 4 guides.rubyonrails.org/v4.0.6/form_helpers.html 后。我正在尝试上传没有任何 gem 的图像,但是当点击创建按钮时,我的图片字段为空。
这是我的控制器:
class ImagesController < ApplicationController
before_action :set_image, only: [:show, :edit,:upload, :update, :destroy]
# GET /images
# GET /images.json
def index
@images = Image.all
end
# GET /images/1
# GET /images/1.json
def show
end
# GET /images/new
def new
@image = Image.new
end
# GET /images/1/edit
def edit
end
# POST /images
# POST /images.json
def create
@image = Image.new(image_params)
if params[:image].present?
file = params[:image][:picture]
File.open(Rails.root.join('app','assets', 'images', file.original_filename), 'wb') do |f|
f.write(file.read) …Run Code Online (Sandbox Code Playgroud) 我在osx yosemite 10.10.1中安装rails时遇到此错误
mezbah$ gem install rails --no-ri --no-rdoc
ERROR: Error installing rails:
invalid gem: package is corrupt, exception while verifying: undefined method `size' for nil:NilClass (NoMethodError) in /Users/mezbah/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/cache/nokogiri-1.6.6.2.gem
mezbah$ gem install nokogiri
ERROR: Error installing nokogiri:
invalid gem: package is corrupt, exception while verifying: undefined method `size' for nil:NilClass (NoMethodError) in /Users/mezbah/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/cache/nokogiri-1.6.6.2.gem
Run Code Online (Sandbox Code Playgroud)
任何的想法??
为什么我看到这个警告?
me = { 'name' => 'mezbah'}
me.index('mezbah') # => warning: Hash#index is deprecated; use Hash#key
Run Code Online (Sandbox Code Playgroud)