在我的应用程序的某个地方我使用
Rails.cache.write 'some_key', 'some_value', expires_in: 1.week
Run Code Online (Sandbox Code Playgroud)
在我的应用程序的另一部分中,我想弄清楚该缓存项还剩多少时间。
我怎么做?
我在Ruby中有这么简单的代码(test.rb):
#! /usr/bin/env ruby
require 'optparse'
OptionParser.new do |option|
option.on("--sort", "Sort data") do
puts "--sort passed"
end
end.parse!
Run Code Online (Sandbox Code Playgroud)
然后我运行它:./test.rb -s得到:
--sort passed
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
我希望唯一--sort(长)选项有效,而不是短选项.
我怎么得到它?
我想使用关注点app/controllers/concerns/likeable.rb和app/models/concerns/likeable.rb. 第一个用于控制器,第二个用于模型。
如果我创建两个文件,则仅加载第一个文件。
解决这个问题的最佳方法是什么?
我想要映射w!在vim中使用sudo 静默保存文件(无需按[Enter]和[L]键).
这是一条完美运作的线:
command! W :execute ':silent w !sudo tee % > /dev/null' | :edit!
Run Code Online (Sandbox Code Playgroud)
但它是W,而不是W!(带惊叹号)
我怎么做到的?
我有这样一个数组: ["c", "-b", "a"]
["c", "-b", "a"].sort! 回报 ["-b", "a", "c"]
我希望它被排序为 ["a", "-b", "c"]
如何从排序中排除减号?获得它的最简单方法是什么?
我有一个简单的应用程序,在数据库和"多对多"关系中有3个表.
# Model Employee
class Employee < ActiveRecord::Base
has_and_belongs_to_many :phonenumbers
accepts_nested_attributes_for :phonenumbers, :allow_destroy => true
attr_accessible :last_name, :first_name, :middle_name, :phonenumbers_attributes
end
# Model Phonenumber
class Phonenumber < ActiveRecord::Base
has_and_belongs_to_many :employees
attr_accessible :number
accepts_nested_attributes_for :employees
end
Run Code Online (Sandbox Code Playgroud)
我有'employees_phonenumbers'连接表与'employee_id'和'phonenumber_id'列.
# View
<%= form_for @employee, :url => { :action => :create } do |f| %>
<%= f.label "Last name" %>
<%= f.text_field :last_name %>
<%= f.label "First name" %>
<%= f.text_field :first_name %>
<%= f.label "Middle name" %>
<%= f.text_field :middle_name %>
<%= f.fields_for …Run Code Online (Sandbox Code Playgroud) 默认情况下,当我按下insert键时,vim切换到该INSERT模式.如果我insert再次按下键,vim会切换到该REPLACE模式.
我想按键切换INSERT/NAVIGATION模式insert.
即:insert按键 - >获取INSERT模式.按下insert键再次- >找回NAVIGATION状态.
我怎么做到的?
ruby ×2
vim ×2
activerecord ×1
arrays ×1
caching ×1
forms ×1
optionparser ×1
sorting ×1
validation ×1