虽然有点砸场子 ,但我更推荐用 https://devdocs.io/,文档种类更多,也能自己搭,首次打开后会缓存到本地,之后打开速度就特别快。
用 eval, 例如
eval("$#{$key}")
挺有趣的,招聘页面检查元素,藏了个 base64 的密文
楼主对 autoload 的理解是对的
autoload :Base
会在引用 Base 常量,按需执行
require('main/base')
但 require 查找文件是根据$LOAD_PATH
来找的,参考 wiki
https://ruby-china.org/topics/28453
楼上 $:
就是$LOAD_PATH
简写
https://api.rubyonrails.org/classes/ActiveRecord/NestedAttributes/ClassMethods.html
params 里参数名改为 wives_attributes
9
Both signal handlers are called 因为 trap 会返回上一个信号的 handler https://ruby-doc.org/core-2.2.0/Signal.html#method-c-trap
trap returns the previous handler for the given signal
我的经验是 ajax 的重定向应该
render js: 'window.location.href=xxxxx'
也可以在非 view 的地方使用
ActionController::Base.helpers.number_to_currency 7777777
你看看《Rails 入门》后续的 5.11 节
如果传入和实例变量(@article)同名的符号(:article),也会自动产生相同效果
所以
form_for :article
等同于
form_for @article
::Equipment::Accepting 已经解决了常量查找的问题。
tables not exist 是说数据库中不存在名字叫 Accepting 的表,你应该看看数据库表的名字是什么,对应改变 model 的名字。或者在 model 中写
self.table_name = "你的表名"
migration 里也要 establish_connection, 参考https://stackoverflow.com/questions/20502806/rails-migrate-with-different-databases
不好意思,我解释错了,应该是跟执行 ruby 的进程的文件夹有关。参考如下的 require 例子
https://rubyplus.com/articles/4661-The-require-and-load-path-in-Ruby
因为这两文件在同一文件夹下,所以可以 load 成功吧。
当前文件夹下找不到,再去 load_path 下找吧。