#12 楼 @zhangyuxiu 那啥,趁你还没花多少时间进去,赶紧把发行版换掉……不要用 Fedora……
#10 楼 @zhangyuxiu 没事别 sudo
我觉得这样就可以了(。・ω・。)
class Order
def ❨╯°□°❩╯︵(┻━┻)
create_or_use_list ┻━┻
end
def self.(\—_—)\(params)
self.new(params)
end
private
def create_or_use_list(list_params)
# logic goes here
end
end
class OrdersController < ApplicationController
def create
@order = Order.(\—_—)\ ┯━┯
if @order.❨╯°□°❩╯︵ ┻━┻
flash[:notice] = t('common.update_success')
end
respond_with @order
end
def ┯━┯
params.require(:order).permit(:name, order: [:name, :number, :about])
end
def ┻━┻
┯━┯.delete :order
end
end
用 calibre 什么的随便转下格式就行了
直接看他的 vimrc 就行了: https://github.com/knwang/dotfiles/blob/master/.vimrc
#18 楼 @quakewang json 确实不大,于是刚刚试着让 json 长度变大,将 index 里面 per_page 从 8 增加到 25,差距反而更大了……
8 Time per request: 115.210 [ms] vs 148.235 [ms] 25 Time per request: 150.185 [ms] vs 212.686 [ms]
cache 是用的 redis:
config.cache_store = :redis_store, "redis://localhost:6379/0/cache", { expires_in: 90.minutes }
顺便吐槽下新版的 nginx,内置了 etag 然后强制隐藏了上游 etag,没法用 rails 里面的 etag 了……
add_header ETag $upstream_http_etag;
都没用……
好奇怪啊,我试了下在 json 里面用 cache digest,然后用 ab 测试,响应时间反而显著变慢了……是不是也就是说如果生成的 json 不大,就根本没必要 cache 么……
json.cache! @users do |json|
json.users @users do |user|
json.id user.id
json.user_name user.user_name
...
end
end
Concurrency Level: 100
Time taken for tests: 7.412 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 6368120 bytes
HTML transferred: 4215000 bytes
Requests per second: 674.61 [#/sec] (mean)
Time per request: 148.235 [ms] (mean)
Time per request: 1.482 [ms] (mean, across all concurrent requests)
Transfer rate: 839.06 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.5 0 5
Processing: 12 146 31.5 144 417
Waiting: 12 146 31.5 144 417
Total: 17 146 31.4 144 417
Percentage of the requests served within a certain time (ms)
50% 144
66% 152
75% 158
80% 161
90% 170
95% 184
98% 232
99% 291
100% 417 (longest request)
vs
json.users @users do |user|
json.id user.id
json.user_name user.user_name
...
end
Concurrency Level: 100
Time taken for tests: 5.761 seconds
Complete requests: 5000
Failed requests: 0
Write errors: 0
Total transferred: 6368028 bytes
HTML transferred: 4215000 bytes
Requests per second: 867.98 [#/sec] (mean)
Time per request: 115.210 [ms] (mean)
Time per request: 1.152 [ms] (mean, across all concurrent requests)
Transfer rate: 1079.55 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.6 0 6
Processing: 18 113 27.5 109 407
Waiting: 18 113 27.5 109 407
Total: 23 113 27.4 109 407
Percentage of the requests served within a certain time (ms)
50% 109
66% 118
75% 125
80% 129
90% 137
95% 145
98% 166
99% 243
100% 407 (longest request)
#31 楼 @ronbin 那个 required 应该是 simple_form 加的,我都没动它……
其实那 helper 没干啥特别的,只是用 simple_form 的 custom form builder 的功能,直接将后端模型塞入到相应的options[:input_html]['data-ng-model']
里面而已,写的很难看很罗嗦,但整个全部不到 50 行,所以真的是很简单的……那个 data-ng-disable 只是简单的覆盖掉 form builder 原来的 button……
def button(name, options={})
options[:class] ||= ''
options[:class] += ' btn'
options[:class].sub!(/^\s+/, '')
content_tag(:div, name, options.merge(
'data-ng-click' => 'submit()',
'data-ng-disabled' => 'form.$invalid'
))
end
#16 楼 @nightire So, what's your point then? You are now useing some pure front-ended
helper which is written in javascript that are better than Rails helper which is written in ruby? Ok, If you have something better, just show us the code, please.
PS.说了半天你怎么知道我就没看过那点东西呢?我会告诉你我最后选 angular 没选 ember 的原因之一就是看了 discourse 那些一坨坨的玩意被吓到了么……
#11 楼 @nightire 哟,满满的优越感……随便一个语法简答的模板引擎就能满足你了?非要我把生成的 html 帖出来比较么 源码:
= ng_form_for(User.new, controller: 'RegistrationNewCtrl') do |f|
= f.input :user_name, placeholder: '输入你的用户名'
= f.input :email, placeholder: '[email protected]'
= f.input :password, placeholder: '长度在6位以上'
= f.input :password_confirmation, placeholder: '确认密码'
= f.button '注册'
<form accept-charset="UTF-8" action="/users" class="simple_form new_user" data-ng-controller="RegistrationNewCtrl" data-ng-submit="submit()" id="new_user" method="post" name="form" novalidate="novalidate">
<div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" />
</div>
<div class="control-group string required user_user_name"><label class="string required control-label" for="user_user_name"><abbr title="required">*</abbr>
用户名</label>
<div class="controls"><input class="string required" data-ng-model="user.user_name" id="user_user_name" name="user[user_name]" placeholder="输入你的用户名" type="text" />
<p class="help-block">{{errors.user_name}}</p>
</div>
</div>
<div class="control-group email optional user_email"><label class="email optional control-label" for="user_email">Email</label>
<div class="controls"><input class="string email optional" data-ng-model="user.email" id="user_email" name="user[email]" placeholder="[email protected]" type="email" value="" />
<p class="help-block">{{errors.email}}</p>
</div>
</div>
<div class="control-group password optional user_password"><label class="password optional control-label" for="user_password">密码</label>
<div class="controls"><input class="password optional" data-ng-model="user.password" id="user_password" name="user[password]" placeholder="长度在6位以上" type="password" />
<p class="help-block">{{errors.password}}</p>
</div>
</div>
<div class="control-group password optional user_password_confirmation"><label class="password optional control-label" for="user_password_confirmation">确认密码</label>
<div class="controls"><input class="password optional" data-ng-model="user.password_confirmation" id="user_password_confirmation" name="user[password_confirmation]" placeholder="确认密码" type="password" />
<p class="help-block">{{errors.password_confirmation}}</p>
</div>
</div>
<div class="btn" data-ng-click="submit()" data-ng-disabled="form.$invalid">注册</div>
</form>
这玩意在我写完ng_form_for
这 helper 之前,本来就是用 slim 手写的,重复得都想吐,同学你可以试着用 Emblem 重写一遍
就算是完全用 angular 写,你也还得写 template 啊,那么 rails 的 view 还是要的,毕竟手写 html 什么的太特么反人类了……另外不用 assets 难道不用 css 么
为啥用 goagent 和 ssh 都翻不开……
首先,用 angularjs 最好别用 jquery,这是坏习惯,要改 Don't even use jQuery 然后谁告诉你
AngularJS 这些东西不管数据是不是加载完成,都会第一时间显示页面
去查查 resolve 还有 $q怎么用……
难道你的意思是想要
fields.delete("created_at")
field :created_on, as: :created_at
看不懂这样改个名字有啥优势……
其实我个人超讨厌 describe,比较喜欢写这样的:
describe User do
valid_addresses = %w[[email protected] [email protected] [email protected]]
invalid_addresses = ['user@foo,com', 'user_at_foo.org', 'first.last@foo.', '']
let(:user) { create :user }
subject { user }
context 'DB Implementation' do
let(:user) { create :user }
it { should have_field(:user_name).of_type(String) }
it { should have_field(:email).of_type(String)
.with_default_value_of('') }
it { should have_field(:encrypted_password)
.of_type(String).with_default_value_of('') }
it { should have_many(:notifications) }
it { should have_many(:photos) }
it { should have_one(:profile) }
it { should validate_presence_of(:user_name) }
it { should validate_presence_of(:email) }
it { should validate_uniqueness_of(:user_name) }
it { should validate_uniqueness_of(:email) }
it { should validate_confirmation_of(:password)}
valid_addresses.each do |valid_address|
it { should validate_format_of(:email).to_allow(valid_address) }
end
invalid_addresses.each do |invalid_address|
it { should validate_format_of(:email).not_to_allow(invalid_address) }
end
end
its(:admin?) { should be_false}
context 'Admin' do
let(:user) { create :admin }
its(:admin?) { should be_true }
end
describe 'email' do
context 'when set without token' do
before { user.email = '[email protected]'; user.save! }
its(:email) { should_not == '[email protected]' }
end
end
end