Home
Yates Zhang
Cancel

Rails 让model显示validation错误信息

refer to: https://stackoverflow.com/questions/31806431/rails-validation-knowing-which-field-is-invalid product.valid? # => run validation callbacks, 这个方法一定要调用,否则不会展示下面的内容 product.errors...

caddy 的基本用法和使用

caddy: 一种类似于轻量nginx吧 非常好玩,文件夹中: caddy 命令, CaddyFile 配置CaddyFile即可。 然后 ./caddy restart 就行。 等同于nginx -s reload Caddy 与rails配合使用 rails 正常启动: bundle bundle exec rails webpacker:install bundle exec...

Rails belongs_to 在最新版本默认是 required

refer to: https://www.bigbinary.com/blog/rails-5-makes-belong-to-association-required-by-default 在目前的版本中(貌似 >= Rails 5? ) 只要你写了belongs_to , 那么默认该列就是必须的. 例如 class Apple belongs_to :fruit ...

Rails active record的模型中,不能用hash 作为列名字

如题。否则会报错 Type error,  can not convert String to Integer 

Rails send emails, content, body ,attachment 附件

refer to: https://api.rubyonrails.org/classes/ActionMailer/Base.html class NotifierMailer < ApplicationMailer def welcome(recipient) attachments["free_book.pdf"] = File.read("path/to...

Rails rails error command webpack not found

refer to: https://stackoverflow.com/questions/58065428/rails-vanilla-rails-6-0-error-command-webpack-not-found bundle exec rails webpacker:install

Rails 配置项 figaro

参考:  https://github.com/laserlemon/figaro 跟  rails-settings 很相似 用法: gem 'figaro' $ bundle exec figaro install 然后就会生成 config/application.yml host: 'localhost' port '3306' puts ENV['hos...

Ruby grape 使用logger

用了Grape之后,才发现,这个东东是默认没有日志的.所以就看不到 每次请求耗费多长时间 ( Completed in xxx ms ) 所以,有个Gem:  https://github.com/aserafin/grape_logging 1. Gemfile:  gem 'grape_logging' 2. 在每个grape API的方法前面,都要加上: mod...

Puma + nginx 的部署

puma 这个服务器第一次听说是在2012,2013年。 还在优酷的时候,当时的小弟 海龙在一个项目中开始使用它。 由于我对于thin用的特别顺手,就没有估计到这个服务器。 直到今天。项目中需要使用websocket.  thin 已经无法满足需求了。 步骤:  1. 建立puma 的配置文件: threads_count = 32 threads 4, 32 port 8888 envi...

Rails 使用annotate_model 对model进行注释

参考:https://github.com/ctran/annotate_models 这个gem 会自动的在某个model下面,加上注释.  # == Schema Info # # Table name: trips # # local :geometry point, 4326 # path :geometry ...