我的网站部署在heroku上.Time.now今天将返回,但是记录的created_at字段(现在创建)将在明天说明.我认为这与服务器时间有关?
有没有办法确保它们是一样的?最好的,艾略特
更新所以我做了这个"heroku rake time:zones:us"
它给了我:
* UTC -10:00 *
Hawaii
* UTC -09:00 *
Alaska
* UTC -08:00 *
Pacific Time (US & Canada)
* UTC -07:00 *
Arizona
Mountain Time (US & Canada)
* UTC -06:00 *
Central Time (US & Canada)
* UTC -05:00 *
Eastern Time (US & Canada)
Indiana (East)
Run Code Online (Sandbox Code Playgroud)
但是,当我在我的环境中设置config.time_zone ='UTC -05:00'时,应用程序无法启动.有任何想法吗?
我看了http://railscasts.com/episodes/73-complex-forms-part-1和http://railscasts.com/episodes/74-complex-forms-part-2但它似乎不起作用我在尝试代码时 - 从那时起我的假设在rails中发生了很多变化.第二个问题是我正在使用JQuery.
有没有人知道在线的任何教程可能会显示更简单的方法吗?我已经制作了一个嵌套的模型表单 - 所以它实际上只是添加/删除字段动态地分解了我.
我一直试图让Resque(使用Resque服务器)和RedisToGo在heroku(雪松)上工作一段时间,但我一直遇到这个错误:
Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (ECONNREFUSED)):
Run Code Online (Sandbox Code Playgroud)
它在本地工作,我可以在我的应用程序的Heroku控制台中访问redis.
我的Procfile有:
web: bundle exec thin start -p $PORT -e $RACK_ENV
web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
resque: env TERM_CHILD=1 RESQUE_TERM_TIMEOUT=10 bundle exec rake resque:work
Run Code Online (Sandbox Code Playgroud)
我的Gemfile有:
gem 'redis'
#Background queue
gem 'resque', '~> 1.22.0', :require => "resque/server"
Run Code Online (Sandbox Code Playgroud)
LIB /任务/ resque.rake:
require 'resque/tasks'
task "resque:setup" => :environment do
ENV['QUEUE'] = '*'
end
desc "Alias for resque:work (To run workers on Heroku)"
task "jobs:work" => "resque:work"
Run Code Online (Sandbox Code Playgroud)
routes.rb中:
mount Resque::Server.new, :at => …Run Code Online (Sandbox Code Playgroud) 我正在使用https://github.com/crowdint/rails3-jquery-autocomplete,它似乎正在运行.唯一的问题是让我说我有一个字段在所有帖子标题上执行自动完成,但我希望它只显示用户创建的帖子的标题.
有没有办法做这样的事情?即find_by还是什么?
谢谢!
-Elliot
编辑
它在文档中说:
If you want to display a different version of what you're looking for, you can use the :display_value option.
This options receives a method name as the parameter, and that method will be called on the instance when displaying the results.
class Brand < ActiveRecord::Base
def funky_method
"#{self.name}.camelize"
end
end
class ProductsController < Admin::BaseController
autocomplete :brand, :name, :display_value => :funky_method
end
In the example above, you will search by name, but the …Run Code Online (Sandbox Code Playgroud) 我正在尝试每天记录一些数据,自动在我的rails应用程序中.我想知道是否有人知道一个很好的解决方案呢?我找到了https://github.com/javan/whenever,但我想确保在选择之前知道所有选项.
谢谢!
埃利奥特
我正在尝试在我的应用程序中做一些事情,如果用户在 90 天内没有登录,他们的帐户将被设置为未确认,他们将收到电子邮件以重新确认他们的电子邮件地址。
我知道我可以重新发送电子邮件:
Devise::Mailer.confirmation_instructions(@user).deliver
Run Code Online (Sandbox Code Playgroud)
我在架构中看到这些相关字段 -
t.string "unconfirmed_email"
t.string "confirmation_token"
t.datetime "confirmed_at"
t.datetime "confirmation_sent_at"
Run Code Online (Sandbox Code Playgroud)
是否将它们全部设置为 nil,并将未经确认的电子邮件返回到常规电子邮件使这项工作有效?
我正试图找出一个好方法来解决这个问题.
假设我有一个包含帖子,标题和不同状态ID的表格.
在我的控制器索引中,我有:
@posts = Post.all
Run Code Online (Sandbox Code Playgroud)
然后在我的模型中我有:
def check_status(posts)
posts.each do |post|
# logic here
end
end
Run Code Online (Sandbox Code Playgroud)
所以在我的控制器中我有:
@posts.check_status(@posts)
Run Code Online (Sandbox Code Playgroud)
但加载索引时我收到以下错误:
undefined method check_status for <ActiveRecord::Relation:>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
继承人我正在努力实现的目标:
我想检查标签是否已存在.如果是这样,我想使用tag_join记录的现有标记,而不是创建新的标记记录.
这是我当前的代码,它不起作用.
class Tag < ActiveRecord :: Base
belongs_to :user
belongs_to :tag_join
belongs_to :post
before_create :check_exists
def check_exists
tag = Tag.where(:name => self.name, :user_id => current_user.id)
if tag.nil?
tag = Tag.create(:name => self.name, :user_id => current_user.id)
end
end
end
Run Code Online (Sandbox Code Playgroud)
这不起作用,我在创建任务时遇到错误...(服务器实际上只是超时 - 我没有收到特定的错误).
有任何想法吗?
Tokland说我通过告诉它再次创建标签来创建一个无限循环 - 所以我尝试了这个:
def check_exists
tag = Tag.find_by_name_and_user_id(:name => self.name, :user_id => current_user.id)
if tag != nil
self.id = tag.id
end
end
Run Code Online (Sandbox Code Playgroud)
仍然得到服务器超时
编辑:我不确定这是否重要,但标签的添加方式类似于"http://railscasts.com/episodes/73-complex-forms-part-1
它们嵌套在帖子中,并使用类似这样的东西:
def tag_attributes=(tag_attributes)
tag_attributes.each do |attributes|
tags.build(attributes)
end …Run Code Online (Sandbox Code Playgroud) 我有一个名为posts的模型,它有很多附件.
附件模型使用回形针.
我创建了一个独立的模型来创建附件,工作得很好,这是这里指示的视图(https://github.com/thoughtbot/paperclip):
<% form_for :attachment, @attachment, :url => @attachment, :html => { :multipart => true } do |form| %>
<%= form.file_field :pclip %>
<%= form.submit %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
帖子中的嵌套表单如下所示:
<% @attachment = @posts.attachments.build %>
<%= form_for(@posts) do |f| %>
<% if @posts.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@posts.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @posts.errors.full_messages.each do |msg| %>
<li><%= msg %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="field">
<%= f.label :name %><br …Run Code Online (Sandbox Code Playgroud) ruby-on-rails ×10
ruby ×5
jquery ×2
devise ×1
heroku ×1
javascript ×1
lightbox ×1
paperclip ×1
redis ×1
resque ×1