什么是保持Heroku应用程序活着同时保持1 dyno的最佳解决方案?
这是一个非常小的应用程序,但是不是等待20秒等待将dyno变为现实,如果每隔30分钟就会对我的Heroku应用程序进行一次ping操作以防止它进入睡眠状态,那将会很棒.每隔一小时.
网上的一些解决方案建议使用"New Relic",但我想亲自询问一下,看看2014年是否有新问题的答案.
小信息:我正在运行一个中间人应用程序,在Heroku上使用Puma.
在phoenix framework管道中,我们可以为某些路由启用指定中间件,例如:
defmodule HelloPhoenix.Router do
use HelloPhoenix.Web, :router
pipeline :browser do
plug :accepts, ["html"]
plug :fetch_session
plug :fetch_flash
plug :protect_from_forgery
plug :put_secure_browser_headers
end
pipeline :api do
plug :accepts, ["json"]
end
scope "/", HelloPhoenix do
pipe_through :browser # Use the default browser stack
get "/", PageController, :index
end
scope "/api", HelloPhoenix do
pipe_through :api
end
end
Run Code Online (Sandbox Code Playgroud)
如果请求来自/api,只会触发plug :accepts, ["json"]中间件
如果请求来自/,将触发会话,闪存,...等中间件
如何在rails上实现这一点,如果我使用grape构建api和rails来构建网页并为彼此启用差异中间件?
我试图只根据传递的不同信息显示表中的某些记录,如果没有满足任何要求,它会重定向到主页.代码全部正常运行,只想看看其他人如何解决这个问题
if current_user.admin?
@schedules = Schedule.all
elsif current_user.team_id?
@schedules = Schedule.find_all_by_team_id(current_user[:team_id])
else
redirect_to root_path, :status => 301, :alert => "Please contact your club administrator to be assigned to a team."
return
end
Run Code Online (Sandbox Code Playgroud) 当使用"middleman-blog"扩展在Middleman中生成一个简单的博客时,我得到一个布局文件,它只是产生帖子的内容.
我想要的是获得当前帖子的标题并显示它.
我现在拥有的:
<% blog.articles.each do |article| %>
<%= link_to article.title, article %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
即使只显示单个帖子内容,这也会遍历每个帖子标题.因此它为url/post-title-one输出类似的内容
"只有帖子标题的内容一个"
我想尝试类似的东西
<% blog.articles.each do |article| %>
<%= link_to current_article.title, article %>
<% end %>
Run Code Online (Sandbox Code Playgroud)
但它只是随机吐出两个页面标题.
我想对Task模型执行高级查询(简化版本:
class Task
belongs_to :user_task
belongs_to :customer
end
class UserTask
has_many :tasks
belongs_to: :user
attr_accessible :date
end
class Customer
has_many :tasks
end
Run Code Online (Sandbox Code Playgroud)
我想要构建的是de Task模型的搜索表单,其中包含以下字段:
我创建了一个用于保存搜索的TaskSearch资源,可以想象一个用于查询数据库的大而丑的SQL字符串,但我不确定这是最好的方法.
哪个是ActiveRecord方法?
提前致谢.
我想知道在Rails中输出这个的漂亮方式是什么.
order.items.min.user.email
Run Code Online (Sandbox Code Playgroud)
我想展示电子邮件的价值,我唯一知道的是订单不是零,但是商品和用户可能是零.
我看到的唯一方法是
if !order.items.empty?
if !order.items.min.user.nil?
if !order.items.min.user.email.nil?
order.items.min.user.email
end
end
end
Run Code Online (Sandbox Code Playgroud)
它看起来不是最好的方式,你知道更好的方法吗?