Home
Wade Ruby
Cancel

Ruby 如何require一个文件(rails.root不好使。file.dirname(__file__)好使)

呃。。。算了,这个语法问题,我不想知道为什么。能用就行了。 代码这样写不行,会报错: require File.expand_path(Rails.root + "/lib/api_client.rb")这样写就可以了:</span> require File.expand_path(File.dirname(__FILE__) + "/../lib/api_client.rb...

Ruby Graperequire要正确,否则会报错method_missing':undefinedlocalvariableormethod`parent'

method_missing': undefined local variable or method `parent' for All:Class 如题。

Ruby 方法调用中的星号(star,splatoperator)

说来惭愧。这个知识真的没用到过。  https://stackoverflow.com/questions/918449/what-does-the-unary-operator-do-in-this-ruby-code 在ruby 中, * 也叫 splat operator, 专门为了方便的把一个 数组,作为多个参数传递给某个函数。 def hi name1, name2, ...

Ruby 使用rack Mini Profiler来分析和优化rails

参考 : https://github.com/MiniProfiler/rack-mini-profiler 以及: 这个: 特别有意思, 写的特别好:  https://stackify.com/rack-mini-profiler-a-complete-guide-on-rails-performance/ 1. Gemfile: gem 'rack-mini-...

Rails 使用https的时候记得加上force_ssl这个参数

参考:https://stackoverflow.com/questions/15676596/what-does-force-ssl-do-in-rails 加上之后就好了。 除了不但使用https, 对于cookie 还使用了加密方式。 还允许使用HSTS方式。 修改  config/environments/production.rb 中的 force_ssl=true之后...

Ruby Ruby脚本中的几个基本变量$0,argv

$0:  当前文件的名称。 ARGV: 运行当前rb文件时,添加的 参数。 例如: # test.rb puts "=hi" puts ARGV puts "== $0 : #{$0}" 运行方式:  ruby test.rb  'argv1' =hi argv1 == $0 : test.rb

Ruby 几个图文并茂的profiler工具

参考 https://scoutapm.com/blog/which-rails-profiler-is-right-for-you

Rails Before_action中可以直接render返回

一个例子: before_action :check_failed_and_return, :only => [:test] def test render plain: 'hihihi' end def check_failed_and_return render plain: 'error' # 这里加不加and return 都一样. ...

Rails 关于csrftoken,authenticitytoken一段非常精彩的论述

参考:  https://stackoverflow.com/questions/9141339/how-to-pass-the-csrf-token-between-rails-applications 大意是,难以在两个rails项目中共享csrf token  建议使用 api 加密, public_key ,private key 这样的方式

Ruby Memory_profiling的使用,rails下面。

参考 https://gist.github.com/os6sense/35b9e37eb8f23bdb4a81cde1cc23aa03 add to gemfile : gem 'memory_profiler', require: true, github: 'SamSaffron/memory_profiler' Add a config/initializer/me...

Ruby 创建日期序列

参考: https://stackoverflow.com/questions/19093487/ruby-create-range-of-dates require 'active_support/all' class RailsDateRange < Range # step is similar to DateTime#advance argument def eve...

Ruby 使用ruby Prof,很类似jprofiler的软件

https://github.com/ruby-prof/ruby-prof

Js 申请和使用tradingview

tradingview 是一个不错的K线图的组件.实际上这个组件仅仅是 trading view的一小小小部分. 更多的内容大家可以挖掘. 要想在自己的项目中使用 trading view, 需要提出申请. 填写一个表格. 要包括你个人的github. (这样日后才能访问这个repo)  这个表格不要乱填, 对方会根据你的 网站情况来查看,然后做个比较详细的询问.  最后才会开通g...

Raven Sentryraven:一种检查服务器报错的sass

参考:  https://docs.sentry.io/clients/ruby/integrations/rails/ 之前我的想法是是使用 exception notification .   如果有新工具,我愿意尝试一下. 

Ruby 一次ruby内存泄漏

def professions_w- return RecruitInfo.where(nil) if professions.nil?  # 没问题 + return RecruitInfo.where(nil) if professions.blank?  # 有问题

Ruby 一些不错的gem工具,记录一下

paranoid2:  看起来是把某条记录删除,实际上不删除. hashie : 增强型hash faraday: 发起网络请求 papertrail: 处理log. 把log保存到远程等等. angualr-rails:  rails上运行的angular  datagrid: 用来显示一个可以排序等等的多功能table.  gon: 在js中访问r...

Rails 新增middleware

sinatra 与 rails 的重大区别,就可以认为 后者有茫茫多的middleware.   我们平时用的不多,但是关键时刻需要知道这个,需要读懂代码. 下面就是一个简单的middleware 的使用过程. 具体参考:  http://railscasts.com/episodes/151-rack-middleware?autoplay=true 和 1...

Ruby 使用rbtrace来观察rubyrails的内存情况,判断内存泄漏memoryleaks

参考: https://github.com/tmm1/rbtrace

Rails 重启puma的命令 热启动

常规办法: $ bundle exec pumactl phased-restart -C config/puma.rb 下面是两个不常规的办法: 1. 简单粗暴的 kill -9  2. bundle exec pumactl -P tmp/pids/puma.pid restart 3. 高端麻烦: 保持原有的进程不变,启动新端口的进程, 进程启动后,然后配置ngin...

Ruby 使用newrelic来判断rails应用的问题

new relic: https://rpm.newrelic.com/accounts/51021/applications/setup#ruby 1. 正常注册(进入账户后,居然还看到了我N年前做的项目) 2. 新建。 选择ruby, 等等一系列,跟 oneapm的一毛一样。