我最近设置了Scheduler add并设置了我的rake任务'rake cron_jobs:my_task'.
当我使用'heroku run rake cron_jobs:my_task'进行测试时,它运行正常.
调度程序还声称它在应该运行时运行,并计划再次运行,但没有与该进程相关联的日志记录,如https://devcenter.heroku.com/articles/scheduler#inspecting-output所说应该有.
'heroku ps'显示没有预定的dynos,'heroku logs --ps scheduler.1'没有输出.
我错过了什么?
我正在浏览一个Rails教程,在一个关于用户验证的部分,我一直收到一个错误,告诉我在编辑/创建用户时我的密码确认不能为空.我查看了之前的答案,看起来人们使用的是attr_accessible,它被拉出铁轨.我是一个总计rails/web dev newb所以我不知道如何继续.这个观点是在HAML,对不起,如果这是不好的做法.
模型
class User < ActiveRecord::Base
before_save { self.email = email.downcase }
attr_accessor :name, :email
validates_confirmation_of :password
has_secure_password
validates :name, presence: true, length:{ maximum: 16 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: { with: VALID_EMAIL_REGEX },
uniqueness: { case_sensitive: false }
validates :password, length: { minimum: 6 }
has_one :profile
has_many :posts
end
Run Code Online (Sandbox Code Playgroud)
视图
= form_for(@user) do |f|
- if @user.errors.any?
#error_explanation
%h2
= pluralize(@user.errors.count, "error")
prohibited this username from being saved:
%ul
- @user.errors.full_messages.each do …Run Code Online (Sandbox Code Playgroud) 我正在构建一个gem只是为了完成这些过程,我正在尝试为它添加一个生成器.当我跑步时$ rails g,我的发电机出现了:
Mygem:
mygem:install
Run Code Online (Sandbox Code Playgroud)
但是rails无法识别它
rails g mygem:install
Could not find generator mygem:install.
Run Code Online (Sandbox Code Playgroud)
我的gem指向我的gemfile中的最新版本
#mygem/lib/rails/generators/mygem_generator.rb
require 'rails/generators'
require 'rails/generators/base'
module Mygem
class InstallGenerator < Rails::Generators::Base
def test
puts 'hi'
end
end
end
Run Code Online (Sandbox Code Playgroud)
.
-mygem
- lib
- generators
- mygem
mygem_generator.rb
- mygem
version.rb
mygem.rb
- pkg
mygem-0.0.1.gem
.gitignore
Gemfile
LICENSE.txt
README.md
Rakefile
mygem.gemspec
Run Code Online (Sandbox Code Playgroud)
.
#mygem.gemspec
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'mygem/version'
Gem::Specification.new do |spec|
spec.name = "mygem"
spec.version = Mygem::VERSION …Run Code Online (Sandbox Code Playgroud) 我正在访问 Github 的 v3 rest api,我正在发出 POST 请求,试图在测试 PR 上创建评论。我收到了 200 响应,在检查请求时,它是作为 GET 而不是 POST 发送的:
response = HTTParty.post(
"http://api.github.com/repos/my_github/my_repo/issues/1/comments",
body: { body: "works" }.to_json,
headers: {
"Authorization": "Bearer #{ENV['GITHUB_TOKEN']}",
"Content-Type": "application/json",
"User-Agent": ENV["GITHUB_USER_AGENT"]
}
)
response.request
=> #<HTTParty::Request:0x007fdd45a42688
@http_method=Net::HTTP::Get,
@last_response=#<Net::HTTPOK 200 OK readbody=true>,
@last_uri=#<URI::HTTPS https://api.github.com/repos/my_github/my_repo/issues/1/comments>,
@options=
{:limit=>4,
:assume_utf16_is_big_endian=>true,
:default_params=>{},
:follow_redirects=>true,
:parser=>HTTParty::Parser,
:uri_adapter=>URI,
:connection_adapter=>HTTParty::ConnectionAdapter,
:body=>{:body=>"works"},
:headers=>
{:Authorization=>"Bearer my_token",
:Accept=>"application/vnd.github.machine-man-preview+json",
:"Content-Type"=>"application/json",
:"User-Agent"=>"me"}},
@path=#<URI::HTTPS https://api.github.com/repos/my_github/my_repo/issues/1/comments>,
Run Code Online (Sandbox Code Playgroud)
响应正文是对该 PR 的所有评论的列表,它是对同一 url 的 GET 请求。我不知道为什么它不发送 POST。任何帮助表示赞赏。
我对Rails,数据库和Web开发都很陌生,现在我的功能正在运行,但我100%确定它不是最干净或最Ruby-esq的方式.基本上我想使用两个单独的链接,按不同的列对同一个表进行排序,而不使用两个控制器操作和两个视图.我宁愿只使用一个索引操作来获取一个参数,该参数指示如何对返回的数据进行排序.
电流控制器:
Controller
def index
@casinos = Casino.order('name ASC')
end
def casinos_by_region
@casinos = Casino.order('location ASC')
end
Run Code Online (Sandbox Code Playgroud)
和视图中的链接
%h3 Sort by:
= link_to 'Name', casinos_path
%br
= link_to 'Location', casinos_by_region_path
Run Code Online (Sandbox Code Playgroud)
我阅读了文档,但是我没有看到使用link_to路径将参数从视图传递给控制器的明显方法?我知道我可以通过其他方式做到这一点,但我拒绝相信我不能这样做.抱歉这个愚蠢的问题!
我是 Docker 新手,正在尝试为这个新的 Rails 7 应用程序创建一个 Dockerfile。我使用 vips 而不是 imagemagick 来提高内存。
我的本地机器是 Mac,因此brew install vips可以处理我的非 docker 开发流程,但使用 ruby-vips gem 或从源代码安装的情况不太好。
运行$ docker compose up结果为:
/usr/local/bundle/gems/ffi-1.15.5/lib/ffi/library.rb:145:in block in ffi_lib': Could not open library 'vips.so.42': vips.so.42: cannot open shared object file: No such file or directory. (LoadError)
Run Code Online (Sandbox Code Playgroud)
使用以下 docker-compose.yml:
version: "3.9"
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: password
web:
build: .
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b …Run Code Online (Sandbox Code Playgroud) 我将我的路线设置为
scope "/admin" do
resources :profiles
end
Run Code Online (Sandbox Code Playgroud)
所以我用/ admin/profiles获得了预期的路由.我想从显示操作中排除这个前缀.是否有捷径可寻?我在文档中看到的每个解决方案都是围绕嵌套资源的,我确信我忽略了一些东西.谢谢!
如果我对menuInput使用0或9,则以下代码可以正常工作,循环再次迭代.如果我使用10,则满足循环条件并退出.我想这compareTo似乎只是我用这种方式的第一个价值?当我创建menuInput 99时,循环再次迭代.我是初学者,我不知道该替换什么compareTo.TY!
do...
code
while (menuInput.compareTo("8") > 0 || menuInput.compareTo("1")<0);
Run Code Online (Sandbox Code Playgroud)