我是新来的铁轨上的红宝石,卡在约会.我曾经Time.now得到当前的时间.现在我想找出当前周和当月的srart和结束日期.例如:
如果Time.now还给我 -
2012-08-13 15:25:35 +0530
Run Code Online (Sandbox Code Playgroud)
那么本周的开始和结束日期是:
2012-08-12 - 2012-08-18
Run Code Online (Sandbox Code Playgroud)
那么当月的开始和结束日期是:
2012--08-01 - 2012-08-31
Run Code Online (Sandbox Code Playgroud)
我正在使用代码实现相同的:
Time.now.wday
=> 1
Time.now - 1.day
=> 2012-08-12 15:31:44 +0530
Time.now + 5.day
=> 2012-08-19 15:32:38 +0530
Run Code Online (Sandbox Code Playgroud)
等等..但我发现这不是一个方便的方法.我确信Ruby on Rails确实拥有更好的解决方案.任何人都可以建议找出相同的..
需要创建一个Rails应用程序,我想在当地时区获取时间,即如果位置是德里,时区应该是IST,如果位置是San Fransisco,时区应该是PDT.
如何在铁轨上的红宝石中实现这一目标?
PS一行代码,可根据位置自动设置时区.
我需要的:
类似于Rails 3中ActionMailer中的before_filter.
问题:
我正在研究Rails 3,并希望在ActionMailer中有一个before_filter.检查了actionmailer api并了解了before_action和after_action回调.实施时,它会给出错误:
NoMethodError: undefined method `before_action' for Notifier:Class
Run Code Online (Sandbox Code Playgroud)
后来才知道这篇文章之前没有Rails 3的动作调用
没有任何钩子或宝石,所以我们可以像Rails 3中的before_filter类似.
请帮忙.非常感谢!!
我使用命令安装rvm,按照惯例,应该将rvm作为函数返回
1) bash < <(curl -sk https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer)
2) echo '[[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function' >> ~/.bash_profile
3) source .bash_profile
4) type rvm | head -1
should return ("rvm is a function") // and it returned, rails was perfectly fine yesterday.
Run Code Online (Sandbox Code Playgroud)
它昨天工作得很好,但现在我正在检查铁轨.它说没有安装rails.
type rvm | head -1
returns "RVM is Hashed".
Run Code Online (Sandbox Code Playgroud)
这是我从官方网站获得的东西,但我不知道接下来我应该做什么.所以问题是:
如何在功能模式而不是二进制模式下安装rvm?
我在我的应用程序中使用了before_filter.我有一个方法logged_in?,如果用户登录,则返回true.
def logged_in?
!!current_user
end
def current_user
@current_user = (User.find(session[:user_id]) if session[:user_id]) || false
end
Run Code Online (Sandbox Code Playgroud)
现在在我的用户控制器中,我希望只有在用户未登录时才执行操作.为此,我想在方法中使用not condition with :logged_in?before_filter
before_filter :!(logged_in?)
Run Code Online (Sandbox Code Playgroud)
但这给了我一个错误.我正在拒绝创建一个未登录的新方法.
请帮我找出完成此任务的正确语法.
我正在使用我的Rails项目中的缓存,并希望使特定URL的缓存失效.我得到以下命令来过期对应于传递的URL的片段:
ActionController::Base.new.expire_fragment("localhost:3000/users/55-testing-devise/boards/")
Run Code Online (Sandbox Code Playgroud)
我很困惑将这段代码放在我的Rails项目中,以便在添加文本字段中的url并单击expire按钮后立即执行.
我正在尝试使用doc将ThinkingSphinx集成到我的项目中.对于一个模型与属性和我创建了索引为:User first_namelast_name
User.rb
define_index do
indexes :first_name
indexes :last_name
end
Run Code Online (Sandbox Code Playgroud)
然后我运行命令:
rake ts:index
rake ts:start
Run Code Online (Sandbox Code Playgroud)
这开始我的搜索.当我使用以下命令搜索时,我得到结果:
User.search('swati')
Run Code Online (Sandbox Code Playgroud)
但是当我跑的时候
User.search :with => {:first_name => "swati"}
Run Code Online (Sandbox Code Playgroud)
它给了我错误:
Sphinx Sphinx Daemon returned error: index user_core: no such filter attribute 'first_name'
Sphinx Caught Sphinx exception: index user_core: no such filter attribute 'first_name' (0 tries left)
ThinkingSphinx::SphinxError: index user_core: no such filter attribute 'first_name'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:438:in `block in populate'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:606:in `call'
from /home/swati/.rvm/gems/ruby-1.9.3-p286/gems/thinking-sphinx-2.0.13/lib/thinking_sphinx/search.rb:606:in `retry_on_stale_index' …Run Code Online (Sandbox Code Playgroud) 我在ruby中编写了以下代码来ping网站并检查响应.如果响应成真,网站反应良好,但如果错误则显示网站没有响应.
require 'net/http'
require 'uri'
def ping(host)
begin
url=URI.parse(host)
response=Net::HTTP.get(url)
if response==""
return false
else
return true
end
rescue Errno::ECONNREFUSED
return false
end
end
Run Code Online (Sandbox Code Playgroud)
此代码工作正常,但无法计算网站响应的响应时间.
所以我的问题是如何计算网站响应的响应时间?
我刚刚开始在Golang中编程,想对地图数组进行排序。我有一系列的地图。我们称之为example_array。
example_array = [
[
{ Name: "A", Value: 100 },
{ Name: "B", Value: 60 },
{ Name: "C", Value: 170 },
{ Name: "D", Value: 120}
],
[
{ Name: "A", Value: 64 },
{ Name: "B", Value: 90 },
{ Name: "C", Value: 52 },
{ Name: "D", Value: 98}
],
[
{ Name: "A", Value: 154 },
{ Name: "B", Value: 190 },
{ Name: "C", Value: 179 },
{ Name: "D", Value: 67 }
] …Run Code Online (Sandbox Code Playgroud)