整合下,丢 assets 下面,rails 自带的挺好用。 居然都是女生!!!
能远程实时同步直播嘛?
Sinatra + grape 吧 或者直接上 rails
#13 楼 @prajnamas 赞,逐步替换,保证了项目一直可用。
Use include
, like this:
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
include ApplicationHelper
layout false
end
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem 'byebug'
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem 'spring'
gem 'awesome_print', require: false
gem 'brakeman', require: false
gem 'rails_best_practices', require: false
gem 'rubocop', require: false
gem 'simplecov', require: false
gem 'better_errors'
# gem 'spring-commands-rspec'
# gem 'email_spec'
# gem 'timecop'
# gem 'vcr'
# gem 'fakeweb'
# for test
gem 'rspec-rails'
gem 'factory_girl_rails'
gem 'database_cleaner'
end
group :development do
gem 'letter_opener'
# deploy
#gem 'capistrano'
#gem 'capistrano-rvm'
#gem 'capistrano-rails'
#gem 'capistrano-bundler'
#gem 'capistrano3-puma'
end
group :test do
gem 'shoulda-matchers'
gem 'ffaker'
end
#38 楼 @kayakjiang Thx.
But for someone stepping in to a legacy code base, and adding regression tests, it was very surprising.
I am very surprising.
你有做 spec controller 吗?
require 'rails_helper'
require 'awesome_print'
RSpec.describe Api::V1::UsersController, type: :controller do
describe "GET #show" do
before do
@user = create :user
@request.headers['Authorization'] = "Token token=#{@user.authentication_token}, email=#{@user.email}" # 问题point
end
after do
@request.headers['Authorization'] = nil
end
it "returns http success" do
get :show, { id: @user.to_param, format: :json }
ap response.body # 此处有一个奇怪的反应,打印 "" 这个""不知从何处而来。原因是加入了@request.headers['Authorization'] = "xxx“的设置,去掉就正常返回。
json_hash = JSON.parse(response.body)
expect(json_hash['code']).to eq(200)
end
end
end
console log
""
F
Failures:
1) Api::V1::UsersController GET #show returns http success
Failure/Error: json_hash = JSON.parse(response.body)
JSON::ParserError:
A JSON text must at least contain two octets!
# /home/yy/.rvm/gems/ruby-2.1.6/gems/json-1.8.2/lib/json/common.rb:155:in `initialize'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/json-1.8.2/lib/json/common.rb:155:in `new'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/json-1.8.2/lib/json/common.rb:155:in `parse'
# ./spec/controllers/api/v1/users_controller_spec.rb:20:in `block (3 levels) in <top (required)>'
# ./spec/support/database_cleaner.rb:10:in `block (3 levels) in <top (required)>'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/database_cleaner-1.4.1/lib/database_cleaner/generic/base.rb:15:in `cleaning'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/database_cleaner-1.4.1/lib/database_cleaner/base.rb:92:in `cleaning'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/database_cleaner-1.4.1/lib/database_cleaner/configuration.rb:86:in `block (2 levels) in cleaning'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/database_cleaner-1.4.1/lib/database_cleaner/configuration.rb:87:in `call'
# /home/yy/.rvm/gems/ruby-2.1.6/gems/database_cleaner-1.4.1/lib/database_cleaner/configuration.rb:87:in `cleaning'
# ./spec/support/database_cleaner.rb:9:in `block (2 levels) in <top (required)>'
database_cleaner config
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end
前端模板引擎
我觉得最大的问题在于账户的同步
:plus1:
puma/unicorn/passenger/thin
其实用了再说吧。提前预测是好事。
我也有这个问题,各种谷歌,stackoverflow 无果,ruby 重装了好几遍,最后卸载了oh-my-zsh
。
rvm curWarning! PATH is not properly set up, '/home/xiajian/.rvm/gems/ruby-1.9.3-p551@tophold/bin' is not at first place,
usually this is caused by shell initialization files - check them for 'PATH=...' entries,
it might also help to re-add RVM to your dotfiles: 'rvm get stable --auto-dotfiles',
to fix temporarily in this shell session run: 'rvm use ruby-1.9.3-p551@tophold'.
current
#12 楼 @string2020 完全是个人喜好,用了 N 年 vim 又怎样,我认识一哥们 N 年后换了 sublime。我系统装了 atom, vim, sublime, rubymine,每次第一个出现在脑海的名字就打开。
你应该全部贴在这里,有兴趣的才去关注微信号。
application controller 啊
#5 楼 @chairy11 后面那些带前缀的是 rmagick 或者 minimagick 处理的 补充一下,ruby-china 的 baseuploder 是抽出来的,给其他继承用,外面用的是它的子类。。。见 AvatarUploader
# encoding: utf-8
class ImageUploader < CarrierWave::Uploader::Base
# Include RMagick or MiniMagick support:
# include CarrierWave::RMagick
include CarrierWave::MiniMagick
# Choose what kind of storage to use for this uploader:
storage :file
# 存放目录,打印出来看看嘛
def store_dir
p model.class.to_s.underscore
p mounted_as
p model.id
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
# 这里的就是minimagick处理的,文件名会保存为thumb_#{MD5}.extention(png/jpg),也就是上面多出的四个带前缀的文件,big_xxx.png。相当于resize为200*200,下同
version :thumb do
process :resize_to_fit => [200, 200]
end
version :small do
process :resize_to_fit => [32, 32]
end
version :mid do
process :resize_to_fit => [48, 48]
end
version :large do
process :resize_to_fit => [72, 72]
end
# 格式白名单
def extension_white_list
%w(jpg jpeg gif png)
end
# 文件名没必要纠结吧,有中文就写成这个
def filename
if original_filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path))
"#{@name}.#{file.extension}"
end
end
end
又出新品啦!赞
哥们哪里人?