当我使用C#或Perl时,有一些有用的工具,如StyleCop,FxCop,Perl :: Critic和Perltidy.他们可以自动检查或格式化我的代码.那么,Ruby或Rails有没有相同的工具?我在谷歌上找到了一些工具,但我觉得它们不经常维护.
我想将我的Git项目中的所有erb文件重命名为haml.(比如index.html.erb到index.html.haml)
如果我重命名每个文件,我必须输入以下命令超过三十次.
$ git mv app/views/pages/index.html.erb app/views/pages/index.html.haml
Run Code Online (Sandbox Code Playgroud)
我尝试了下面的命令,但它没有用.
$ git mv app/views/**/*.erb app/views/**/*.haml
usage: git mv [options] <source>... <destination>
-n, --dry-run dry run
-f, --force force move/rename even if target exists
-k skip move/rename errors
Run Code Online (Sandbox Code Playgroud)
我怎样才能立刻重命名它们?
我无法用自制软件安装postgresql.
$ brew install postgresql
Error: Could not create /usr/local/Cellar
Check you have permission to write to /usr/local
Run Code Online (Sandbox Code Playgroud)
我不确定自制软件是否安装得很好.如果您需要更多信息,我会更新.
我试图在我的Ruby 1.9环境中安装metric_fu,但由于下面的问题它失败了:
$ gem install metric_fu
...
Fetching: rcov-1.0.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing metric_fu:
ERROR: Failed to build gem native extension.
/Users/xxx/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
**** Ruby 1.9 is not supported. Please switch to simplecov ****
Run Code Online (Sandbox Code Playgroud)
它说"切换到simplecov",但该怎么做?
更新:安装rcov 0.9.11后恢复.我在这里发现了同样的问题:
我想在 Rails 7.0 应用程序中使用 bootstrap-icons,但图标已折叠。
它应该显示“加号”图标(该图像位于我的旧应用程序中)。
我还收到 ActionController::RoutingError。
08:05:31 web.1 | Started GET "/fonts/bootstrap-icons.woff2?30af91bf14e37666a085fb8a161ff36d" for ::1 at 2021-12-30 08:05:31 +0900
08:05:31 web.1 |
08:05:31 web.1 | ActionController::RoutingError (No route matches [GET] "/fonts/bootstrap-icons.woff2"):
08:05:31 web.1 |
08:05:31 web.1 | Started GET "/fonts/bootstrap-icons.woff?30af91bf14e37666a085fb8a161ff36d" for ::1 at 2021-12-30 08:05:31 +0900
08:05:31 web.1 |
08:05:31 web.1 | ActionController::RoutingError (No route matches [GET] "/fonts/bootstrap-icons.woff"):
Run Code Online (Sandbox Code Playgroud)
以下是我所做的步骤:
创建了一个新应用程序rails new my-app-name --css bootstrap
跑npm i bootstrap-icons(然后我进入"bootstrap-icons": "^1.7.2"我的package.json)
编辑app/assets/stylesheets/application.bootstrap.scss如下:
@import …Run Code Online (Sandbox Code Playgroud)我想允许日期格式的字符串与干验证宝石,但我不能。
class NewUserContract < Dry::Validation::Contract
params do
optional(:date).filled(:date)
end
end
contract = NewUserContract.new
contract.call(date: Date.today)
#=> #<Dry::Validation::Result{:date=>Tue, 14 Jan 2020} errors={}>
# I want to allow date formatted string
contract.call(date: '2020-01-20')
#=> #<Dry::Validation::Result{:date=>"2020-01-20"} errors={:date=>["must be a date"]}>
Run Code Online (Sandbox Code Playgroud)
日期格式的字符串在 0.13 之前是允许的,但从 1.0 开始似乎被禁止。现在我正在尝试升级 Rails 应用程序中的 dry-validation gem。
编辑
我不知道为什么,但上面的代码现在可以工作了。也许缓存问题?(bin/rake tmp:cache:clear不过我记得我跑过)请忽略这个问题。
我正在为 AWS 开发 Rails 应用程序,并希望为区域名称创建下拉菜单,例如“us-east-1”等。
如果有人已经创建了 gem 来获取它们,我想使用它。有谁知道这样的 gem 或有用的 API?
我的环境是macOS,我没有Windows环境。我正在写一篇关于 Byebug 的博客文章,我想知道它是否完全支持 Windows。这是我得到的信息:
可能行不通?
platform: :mri为 byebug gem添加了选项。(见这里)restart)在他们的 Windows PC 中不起作用。可能有用吗?
我不确定哪个想法是正确的。有人知道吗?
@deivid 说 Byebug 支持 Windows。那么,Gemfile 的有效平台选项是什么?
:platforms => [:mri, :mingw, :x64_mingw]或者:platforms => [:mri, :mswin]?
以下是从本页中摘录的选项。
ruby ×5
byebug ×1
coding-style ×1
dry-rb ×1
gem ×1
git ×1
homebrew ×1
metric-fu ×1
postgresql ×1
windows ×1