我.keep在rails骨架的每个目录中都看到了文件.
那个文件是什么?
它的意义是什么?
我正在观看关于多态关联的RailsCast. http://railscasts.com/episodes/154-polymorphic-association?view=asciicast
有三种不同的模型文章,照片和事件,每个都评论来自Comment.rb.(article_id,photo_id和event_id各自的文章,照片和事件).在列出评论时,他有问题找出列出评论的3个模型中的哪一个,所以他在索引动作中这样做
def index
@commentable = find_commentable
@comments = @commentable.comments
end
def find_commentable
params.each do |name, value|
if name =~ /(.+)_id$/
return $1.classify.constantize.find(value)
end
end
nil
end
Run Code Online (Sandbox Code Playgroud)
我的问题是,是什么$1?
我想让自己熟悉ruby语法和编码样式(我是新手).我遇到了一个使用的代码,<<-这在Ruby中意味着什么?代码是
def expectation_message(expectation)
<<-FE
#{expectation.message}
#{expectation.stack}
FE
end
Run Code Online (Sandbox Code Playgroud)
这只是整个代码的一部分.任何帮助,将不胜感激.
我Stripe用作支付网关.现在有一个大问题困扰我.
我使用下面的代码创建订阅:
<?php
require_once('lib/Stripe.php');
Stripe::setApiKey(API_KEY);
$token = $_POST['stripeToken'];
$customer = Stripe_Customer::create(array(
"card" => $token,
"plan" => $_POST['plan'],
"email" => "fakeuser@gmail.com",
));
Run Code Online (Sandbox Code Playgroud)
这工作得很好,但我不能Charge ID从$customer,我发现有一个在没有办法Stripe API得到它.
如何在创建订阅时获取它?我真的需要Charge ID.
Error running 'env GEM_HOME=/Users/john/.rvm/gems/ruby-2.3.8@global
我2.3.8在 MacOs Catalina 中尝试安装 ruby 时遇到此错误10.15.2
$ rvm install 2.3.8
Searching for binary rubies, this might take some time.
No binary rubies available for: osx/10.15/x86_64/ruby-2.3.8.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for osx.
Certificates bundle '/usr/local/etc/openssl@1.1/cert.pem' is already up to date.
Requirements installation successful.
Installing Ruby from source to: /Users/john/.rvm/rubies/ruby-2.3.8, this may take a while depending on your cpu(s)...
ruby-2.3.8 - …Run Code Online (Sandbox Code Playgroud) 我db/structure.sql用来保存我们的数据库状态,因为我们有PostGIS扩展和内置函数,使得使用schema.rb不切实际.
运行db:structure:dumprails时,有一种奇怪的行为,即在文件底部和靠近底部附近设置搜索路径.这里的问题是顶部的搜索路径不正确,导致db:schema:load失败.
我正在手动编辑它(即添加postgis到顶部搜索路径),但如果我能以某种方式通过转储任务正确设置搜索路径,那将是很好的.
database.yml的
development: &dev
adapter: postgis
database: myapp_dev
host: localhost
encoding: utf8
template: template0 # Required for UTF8 encoding
postgis_extension: true
schema_search_path: "public,postgis"
Run Code Online (Sandbox Code Playgroud)
DB/structure.sql
--
-- PostgreSQL database dump
--
SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
... Table / Sequence / Index creation …Run Code Online (Sandbox Code Playgroud) 我已经在后台使用sidekiq和redis-server发送电子邮件了.
问题:使用同步方法发送电子邮件时可以.即在...applicants_controller.rb
UserMailer.notify_applicant_assignment(current_assigned_user.id, applicant, workflow_step).deliver
Run Code Online (Sandbox Code Playgroud)
但是,当我使用delay方法发送电子邮件时
在 applicants_controller.rb
UserMailer.delay.notify_applicant_assignment(current_assigned_user.id, applicant, workflow_step)
Run Code Online (Sandbox Code Playgroud)
我得到以下错误undefined method 'background_color' for nil:NilClass的/layouts/user_mailer.html.erb:17:
代码里面 mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
include Sidekiq::Worker
default from: CommonConstants::DO_NOT_REPLY_ADDRESS
layout 'user_mailer'
def notify_applicant_assignment(user_id, applicant_id, workflow_step_id)
@user = User.find(user_id)
@organization = @user.organization
@applicant = Applicant.find(applicant_id)
@url = root_url + 'applicants/' + @applicant.id.to_s
@workflow_step = WorkflowStep.find(workflow_step_id)
mail(to: @user.email, subject: 'Applicant Assigned.')
end
end
Run Code Online (Sandbox Code Playgroud)
代码里面 layouts/user_mailer.html.erb
<body style="background:#f4f4f4;">
<table width="100%" bgcolor="<%= @organization.background_color %>" cellpadding="0" …Run Code Online (Sandbox Code Playgroud) 我在内部应用程序共享中发布了我的应用程序。在我分享了下载给自己的链接后,但下载到另一个帐户。我在手机上的 Google Play 中打开了内部应用共享。当我单击下载时,我发现错误 -> 从服务器检索信息时出错。DF-DFERH-01
我最近改变了我的ubuntu到Linux薄荷,所以我需要重新安装我的宝石,但它给了我这个错误....
我已经完成的步骤
Fetching git://github.com/seuros/capistrano-puma.git
error: cannot open .git/FETCH_HEAD: Permission denied
Retrying git fetch --force --quiet --tags
"/home/asad/.bundler/cache/git/capistrano-puma-e90ae8bdcca081264c0ff67caa1d11e89f7a01e0" due to error (2/3): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/asad/.bundler/cache/git/capistrano-puma-e90ae8bdcca081264c0ff67caa1d11e89f7a01e0"` in directory /usr/local/rvm/gems/ruby-2.0.0-p598/bundler/gems/capistrano-puma-7748efb9a53d has failed.
If this error persists you could try removing the cache directory '/home/asad/.bundler/cache/git/capistrano-puma-e90ae8bdcca081264c0ff67caa1d11e89f7a01e0'
error: cannot open .git/FETCH_HEAD: Permission denied
Retrying git fetch --force --quiet --tags "/home/asad/.bundler/cache/git/capistrano-puma-e90ae8bdcca081264c0ff67caa1d11e89f7a01e0" due to error (3/3): Bundler::Source::Git::GitCommandError Git error: command `git fetch --force --quiet --tags "/home/asad/.bundler/cache/git/capistrano-puma-e90ae8bdcca081264c0ff67caa1d11e89f7a01e0"` in directory /usr/local/rvm/gems/ruby-2.0.0-p598/bundler/gems/capistrano-puma-7748efb9a53d …Run Code Online (Sandbox Code Playgroud) 我有很多项目需要维护;它们需要不同的插件才能运行。但是,某些插件很重,导致 VS Code 变慢。
我希望在打开一个项目时应用一组插件,而不是其他项目。这样我的VSCode就会轻量级了。