我已经和Clojure合作了几个星期,主要是使用Lein + Luminus框架.我一直在寻找一种在REPL上调试代码的方法.
在调试和运行时调用方面,我非常喜欢pry(在Ruby上)的工作方式.对于clojure代码有没有相当于pry?或者可能是我错过的技术/工具?
我想我的新升级的应用程序执行数据库相关的操作(Rails的5),我无法执行破坏数据库本地命令.
rails db:reset
或rails db:drop
.
跟踪结果包含以下数据,
rails db:drop --trace
** Invoke db:drop (first_time)
** Invoke db:load_config (first_time)
** Execute db:load_config
** Invoke db:check_protected_environments (first_time)
** Invoke environment (first_time)
** Execute environment
** Invoke db:load_config
** Execute db:check_protected_environments
rails aborted!
ActiveRecord::NoEnvironmentInSchemaError:
Environment data not found in the schema. To resolve this issue, run:
bin/rails db:environment:set RAILS_ENV=development
Run Code Online (Sandbox Code Playgroud)
到目前为止我尝试过的是,
bin/rails db:environment:set RAILS_ENV=development
,不会改变任何仍然发生错误.这些都没有帮助.我正在寻找修复或解决方法.
我正在努力将我的clojure应用程序(使用korma)迁移到Datomic框架,并在我翻译查询时处于循环中.我意识到查询不是完全灵活的(与korma相比),例如我想评估不同变量周围的条件子句.
考虑korma查询,
(select users
(where (or (and {:first_name [= "user"]}
{:last_name [= "sample"]})
{:email [= "user.sample@email.com"]})))
Run Code Online (Sandbox Code Playgroud)
这可以转换为Datomic,有这样的东西吗?
[:find ?e
:where (or (and [?u :user/first-name "user"]
[?u :user/last-name "sample"])
[?u :user/email "user.sample@email.com"])
Run Code Online (Sandbox Code Playgroud)
但这不是推荐的查询方式(根据Datomic docs),因为or子句中使用的所有子句必须使用相同的变量集.如何围绕不同的变量集设置OR子句?
我有一个模型,在和上A
有回调。after_commit
create
update
class A < ApplicationRecord
after_commit :update_xyz, on: [:create, :update]
end
Run Code Online (Sandbox Code Playgroud)
这个用例就是一个 rake 任务。我的 rake 任务尝试创建许多模型A
记录,但必须跳过此update_xyz
回调。
创建记录时是否可以跳过这些回调?我不想为此添加额外的宝石/插件。
我正在尝试在开发模式下部署rails 4应用程序.当我尝试cap deploy:setup时,它表示没有设置暂存.接下来,我根据其建议尝试了cap开发部署,并得到以下错误.请帮我部署一下.
command: cap development deploy
cap aborted!
wrong number of arguments (5 for 1..2)
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/dsl/env.rb:38:in `server'
config/deploy/development.rb:5:in `<top (required)>'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/setup.rb:15:in `load'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/setup.rb:15:in `block (2 levels) in <top (required)>'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/lib/capistrano/application.rb:15:in `run'
/home/divya/.rvm/gems/ruby-2.1.0/gems/capistrano-3.1.0/bin/cap:3:in `<top (required)>'
/home/divya/.rvm/gems/ruby-2.1.0/bin/cap:23:in `load'
/home/divya/.rvm/gems/ruby-2.1.0/bin/cap:23:in `<main>'
/home/divya/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `eval'
/home/divya/.rvm/gems/ruby-2.1.0/bin/ruby_executable_hooks:15:in `<main>'
Tasks: TOP => development
(See full trace by running task with --trace)
Run Code Online (Sandbox Code Playgroud)
使用以下文件: deploy.rb
set :application, 'timeTracker'
set :scm, :git
set :repository, "git@github.com:p/project.git"
set :user, "r"
set :scm_passphrase, "r"
set :branch, "master"
set :deploy_via, :remote_cache
set :stages, …
Run Code Online (Sandbox Code Playgroud) 我在rails应用程序中启动了测试环境,当我使用默认代码测试用户模型时,它会抛出以下错误:
测试代码:
test "the truth" do
assert true
end
1) Error:
UserTest#test_the_truth:
ActiveRecord::RecordNotUnique: Mysql2::Error: Duplicate entry '' for key 'index_users_on_email': INSERT INTO `users` (`created_at`, `updated_at`, `id`) VALUES ('2014-02-01 17:45:51', '2014-02-01 17:45:51', 298486374)
Run Code Online (Sandbox Code Playgroud)
在我的用户模型中,我有以下关联
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
validates :user_name , :email, :first_name ,:last_name , :presence => true
has_many :invitations
has_many :incoming_friends, -> { where(:status => '1') }, :class_name => "User", :foreign_key => "friend_id", :through => :invitations
has_many :outgoing_friends, -> { where(:status => '1') }, :class_name => "User", …
Run Code Online (Sandbox Code Playgroud) 我正在寻找一个简单的解决方案来解析上传到我的应用程序的每个文件,并转换为简单的文本.我的Web应用程序在Clojure上运行,并且更喜欢API来解析各种文件类型.
我正在尝试使用clojure函数来检测传递的值是否为地图.例如,
user=> (if-map {:foo 1}) ;Should return true
true
user=> (if-map "hello") ;Returns false
false
Run Code Online (Sandbox Code Playgroud)
是否有预先建立的功能服务于此?
我有:
s = "like_so__case"
Run Code Online (Sandbox Code Playgroud)
camelize
给出这个:
s.camelize # => "LikeSoCase"
Run Code Online (Sandbox Code Playgroud)
我正在寻找转换为双下划线__
来获得:
"LikeSo__case"
Run Code Online (Sandbox Code Playgroud)
我怎样才能只追踪字符串的某个部分?
clojure ×4
ruby ×2
capistrano ×1
datomic ×1
deployment ×1
file-upload ×1
javascript ×1
string ×1
vpn ×1