Save your time in rails console by using irbrc to provide shortcuts for frequent commands
Finding your own user account in rails console is very frequent command in daily work. But key the full command is very inconvenient and waste time. You can use this technique to save time!
Solution
Edit ~/.irbrc
(or ~/.pryrc
if you are using pry)
class Dev
def self.me
User.find_by_email("your_mail@example.com")
end
end
Then in rails console:
[1] pry(main)> user = Dev.me
User Load (0.3ms) SELECT `users`.* FROM `users` WHERE `users`.`email` = 'your_mail@example.com' LIMIT 1
...
You can put most frequent used commands in there. But watch out for name collision.
p.s. I used to put a
app/models/dev.rb
in every projects. But it gets inconvenient when maintaining too many projects. Also your colleagues might have a different shortcut preferences. So I decided to put them in~/.pryrc
喜歡這篇文章嗎?你可能也會喜歡我的學習電子報,我會分享經過篩選的優質內容 + 學習心得
📚 訂閱我的學習電子報
📖 涵蓋主題:
🧑💻 軟體工程
🎯 生產力
💰 商業理財
🧳 創業
🐱 奇怪的知識增加了
💭 思考人生心得
🎁 現在訂閱就送我個人非常愛用「學習任何領域皮毛的 AI Prompt」!
立即免費訂閱 →
✨ 不浪費你的時間,只分享達到我標準的優質內容