刚发现 ruby 的 if 判断后面可以加 then

用 ruby 11年了才刚发现,还是看源代码发现的:https://github.com/ruby/ruby/blob/0aa404b9573d028d87072f40ecb9b86dc161b7ef/yarp/yarp_compiler.c#L208C9-L208C9 写惯了vb一直对ruby、python的if后面没有then而耿耿于怀,写完if条件后总觉的少了点什么。原来ruby一直是有的,错过了11年。
2023-08-31 11:40 | 阅读 1119 次 | 评论 0 条

livereload.js 嵌入到 rails 的错误页面

寻找rails框架的根目录: rails c 然后 edit ActionView 在vim编辑器底部可以看到文件路径,从而得出框架根目录,然后👇 进入到rails框架的根目录,比如: cd /usr/local/lib/ruby/gems/3.2.0/gems/ 从错误页面找到一段特征代码,然后搜索它寻找错误页面模板: ag '<div class="details">' 找到后,编辑页面 vi actionpack-7.0.5/lib/action_dispatch/middleware/templates/rescues/_request_and_respo...
2023-07-30 01:08 | 阅读 822 次 | 评论 0 条

rails test 测试中屏蔽警告信息的办法

如果出现类似信息 DEPRECATION WARNING: Using legacy connection handling is deprecated. Please set `legacy_connection_handling` to `false` in your application. The new connection handling does not support `connection_handlers` getter and setter. Read more about how to migrate at: https://guides.ru...
2023-07-22 00:29 | 阅读 632 次 | 评论 0 条

rails在控制台更新用户密码

user = User.find_by_email("888888@qq.com") user.password = "123456" user.save
2023-07-12 00:15 | 阅读 633 次 | 评论 0 条

ruby on rails 关闭 csrf token 验证

在 app/controllers/application_controller.rb 加入 “skip_before_action :verify_authenticity_token”,比如: class ApplicationController < ActionController::Base include ApplicationHelper skip_before_action :verify_authenticity_token # 就是加这行 before_action :check_login # and so on .......
2023-07-05 16:49 | 阅读 409 次 | 评论 0 条

Editplus 支持 opalrb 的语法文件

主要扩充了 opal-jquery 的 jquery 方法
2023-06-29 22:53 | 阅读 783 次 | 评论 0 条

rails在development模式下静态文件出现“File not found: /assets/.....”的解决办法

删除public下的子目录assets即可 rm -rf public/assets/ 这个坑爹的坑,坑了爹一整夜👺
2023-06-27 06:41 | 阅读 748 次 | 评论 0 条

rails的irb强行开启自动提示

vi ~/.irbrc IRB.conf[:USE_AUTOCOMPLETE] = true 如果不想让它提示就把这个值设为 false
2023-06-26 21:56 | 阅读 575 次 | 评论 0 条

把常用的方法名多写几遍,加深记忆,简单粗暴有效

记不住去搜索引擎,是下策 去查官方文档,中策 把它记在脑海里,上策
2023-06-08 21:12 | 阅读 3463 次 | 评论 2 条

给rails的ActiveModel::Errors类扩展了两个方法:insert、keep

用例见注释: #coding: utf-8 class ActiveModel::Errors # add的简写方法 # u.errors.append :code, '邮件验证码不正确' def append(*l) self.add l[0], :custom, message: l[1] end # 从开头插入,跟append相反 # u.errors.insert :code, '邮件验证码不正确' def insert(*l) errors = [[l[0], :custom, message: l[...
2022-12-02 23:39 | 阅读 1174 次 | 评论 0 条

rails查看某个模型的所有验证规则

比如User模型,则用: User.validators
2022-10-28 20:28 | 阅读 731 次 | 评论 0 条

rails清空Sprockets缓存

在rails开发中,有时候修改了assets里的静态文件名不生效,可能是Sprockets缓存的问题,可以用下面的命令清空: rake tmp:cache:clear 然后再运行 rails s 即可,初次运行后刷新页面需要很长时间,因为缓存被清空了第一次要建立缓存,后面再刷新就很快了
2022-10-23 00:39 | 阅读 433 次 | 评论 0 条

opal对layer弹层的简单封装

def layer_open(h) type = h[:type] || 1 title = h[:title] skin = h[:skin] || 'layui-layer-rim' area = h[:are] || ['420px', '240px'] content = h[:content] success = h[:success] || proc {} layer_index = ` layer.open({ type: #{type}, title: #{title}, s...
2022-10-22 22:55 | 阅读 800 次 | 评论 0 条

rails使用has_secure_password进行身份验证

生成模型 rails g model User username:string email:string password_digest:string 在user模型加入has_secure_password class User < ApplicationRecord has_secure_password end
2022-10-19 23:43 | 阅读 926 次 | 评论 0 条

opal-jquery对等jquery里面的$(this)

evt.current_target对等$(this),如 Document.find('h1').on :click do |evt| puts evt.current_target.html end 对等jquery的 $('h1').click(function () { console.log($(this).html()) })
2022-10-19 11:59 | 阅读 365 次 | 评论 0 条

rails的数据库字段类型,migrations中常用到

The ActiveRecord data types available in Rails 5. :primary_key :string :text :integer :bigint :float :decimal :numeric :datetime :time :date :binary :boolean ...
2022-10-16 10:50 | 阅读 860 次 | 评论 0 条

ruby on rails 的 update、update_attribute、update_columns 的区别

触发Validation 触发Callbacks 改动updated_at update ✅ ✅ ✅ update_attribute ❌ ✅ ✅ ...
2022-10-14 01:18 | 阅读 449 次 | 评论 0 条

rails把db:migrate对数据库的变动应用到schema.rb

执行完 rake db:migrate 以后再执行 rake db:schema:dump
2022-09-24 15:36 | 阅读 1018 次 | 评论 0 条

rails使用ruby3报错:Unable to load application: LoadError: cannot load such file -- net/smtp

在Gemfile里加入如下3行即可: gem 'net-smtp' gem 'net-imap' gem 'net-pop' 别忘了重新运行:bundle install
2022-04-29 00:14 | 阅读 850 次 | 评论 0 条

githubu[gitlab]的简易安装记录

export GITLAB_HOME=/var/www/www.githubu.com sudo docker run --detach \ --hostname www.githubu.com \ --publish 443:443 --publish 80:80 --publish 23:23 \ --name gitlab \ --restart always \ --volume $GITLAB_HOME/config:/etc/gitlab \ --volume $GITLAB_HOME/logs:/var/log/gitl...
2021-11-16 20:20 | 阅读 407 次 | 评论 0 条
浏览2776848次
文章归档