我有一个名为"users"的模型,我创建了一个新的迁移,将一些列添加到users表中.现在当我运行rake db:migrate时,我得到下面的错误b/c它试图再次创建users表
$ rake db:migrate
== DeviseCreateUsers: migrating ==============================================
-- create_table(:users)
rake aborted!
An error has occurred, all later migrations canceled:
Mysql::Error: Table 'users' already exists: CREATE TABLE `users`.....
Run Code Online (Sandbox Code Playgroud)
为什么要再次创建表?
这是我用来创建新迁移的命令
$ rails generate migration AddDetailsToUsers home_phone:decimal cell_phone:decimal work_phone:decimal birthday:date home_address:text work_address:text position:string company:string
Run Code Online (Sandbox Code Playgroud)
新迁移如下所示:
class AddDetailsToUsers < ActiveRecord::Migration
def change
add_column :users, :home_phone, :decimal
add_column :users, :cell_phone, :decimal
add_column :users, :work_phone, :decimal
add_column :users, :birthday, :date
add_column :users, :home_address, :text
add_column :users, :work_address, :text
add_column :users, :position, :string
add_column …
Run Code Online (Sandbox Code Playgroud) 我在React-Redux应用程序上创建了2条路线.我已经添加了主页和回调URL的github应用程序设置.
1.当您点击此路线时:https://reduxapp.herokuapp.com/signin 您点击Github登录按钮,==> githubGeturi
2. Github使用代码https://reduxapp.herokuapp.com/auth/callback?code=9536286a59228e7784a1重定向, 并触发githubSendCode('9536286a59228e7784a1')操作
您可以在网络呼叫中看到OPTIONS呼叫通过,但POST呼叫永远不会发生.并且您收到控制台错误:
XMLHttpRequest cannot load https://github.com/login/oauth/access_token?client_id=32b70bf671e04762b26c&…_secret=123456789123456789123456789&code=9536286a59228e7784a1. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://reduxapp.herokuapp.com' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
以下是我的行动功能:
const CLIENT_ID = '32b70bf671e04762b26c';
const CLIENT_SECRET = '123456789123456789123456789';
const ROOT_URL = window.location.origin;
const REDIRECT_URL = `${ROOT_URL}/auth/callback`;
const AUTHORIZE_URL = 'https://github.com/login/oauth/authorize';
const ACCESS_TOKEN_URL = 'https://github.com/login/oauth/access_token';
const STATE = _.random(10000);
export function githubGeturi() {
const GITHUB_URL = …
Run Code Online (Sandbox Code Playgroud) 我在尝试创建用户时遇到了这个错误(我正在使用设计宝石).
EOFError (end of file reached):
Run Code Online (Sandbox Code Playgroud)
我之前遇到过这个问题,这是由于我使用zoho邮件的smtp设置.
我相信我的配置是解决问题的原因:
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "smtp.zoho.com",
:port => 465,
:domain => 'example.com',
:user_name => 'user@example.com',
:password => 'password',
:authentication => :login,
:ssl => true,
:tls => true,
:enable_starttls_auto => true
}
Run Code Online (Sandbox Code Playgroud)
现在我们已经向网站添加了SSL,我相信这就是导致此错误发生的原因.
有没有人对SSL的错误或zoho邮件smtp设置有任何了解?
我有一个对话框,其中不包含页面加载的内容,我根据用户点击的链接动态设置对话框的内容.
<p:dialog widgetVar="dlg" modal="true" id="dialog">
<p:panel id="fullArticle">
<h:outputText value="#{content.newsArticle}" escape="false" />
</p:panel>
</p:dialog>
...
...
<p:commandLink value="Read more" actionListener="#{content.getFullArticle}" onclick='dlg.show();' update=":fullArticle">
<f:attribute name="contentId" value="#{news.contentId}" />
</p:commandLink>
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是,当您单击"阅读更多"链接时,它会显示对话框,但对话框不在页面的中心.如果我将commandLink上的udpate属性更改为update=":dialog"
,则对话框会闪烁,就好像它正在打开然后立即关闭一样.
如何更新对话框并使其以动态内容为中心?
鉴于下面的代码,是否可以p
使用Java中的这种for循环样式从属性列表中删除索引?
List<Properties> propertiesList = new ArrayList<Properties>();
String keyToDelete = "blah";
for(Properties p : propertiesList) {
if(p.getKey().equals(keyToDelete)) {
propertiesList.remove(index) //How to remove the element at index 'p'
}
}
Run Code Online (Sandbox Code Playgroud)
这就是我用另一个for
循环完成这个的方法
List<Properties> propertiesList = new ArrayList<Properties>();
String keyToDelete = "blah";
for(int i = 0; i < propertiesList.size(); i++) {
if(p.getKey().equals(keyToDelete)) {
propertiesList.remove(i);
}
}
Run Code Online (Sandbox Code Playgroud) 这似乎是一个非常简单的问题,但我无法弄清楚.
我只是试图断言一个字符串等于"string1"或"string2".
这是我尝试过的,但显然都不起作用.
assertEquals(d.getFormType(), "string1") || assertEquals(d.getFormType(), "string2");
assertEquals(d.getFormType(), "string1" || "string2");
Run Code Online (Sandbox Code Playgroud) 我有一个Google Apps帐户.我正在尝试使用服务帐户代表用户发送电子邮件.
我已经浏览了互联网,没有任何工作,我几乎不知所措.
我跟着Java指南,我仍然继续 com.google.api.client.auth.oauth2.TokenResponseException: 401 Unauthorized
为什么这段代码片段给我401 Unauthorized?
JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(JSON_FACTORY)
.setServiceAccountId("something@something-something.iam.gserviceaccount.com")
.setServiceAccountPrivateKeyFromP12File(new File("path/to/file/myProject.p12"))
.setServiceAccountScopes(GmailScopes.all())
.setServiceAccountUser("user@mydomain.org")
.build();
Gmail gmailService = new Gmail.Builder(httpTransport, JSON_FACTORY, credential)
.setApplicationName("My App") // DOES IT MATTER WHAT THIS IS SET TO?
.build();
MimeMessage mimeMessage = createEmail("myemail@gmail.com", "user@mydomain.org", "Testing", "hey");
sendMessage(gmailService, "me", mimeMessage);
Run Code Online (Sandbox Code Playgroud)
这些方法基本上是从Googles文档中复制/粘贴的:
/**
* Create a MimeMessage using the parameters provided.
*
* @param to email address of the receiver
* @param …
Run Code Online (Sandbox Code Playgroud) 我不知道为什么我的计算机属性错误会产生意外的副作用,如下所示.
错误:
? https://google.com/#q=vue%2Fno-side-effects-in-computed-properties Unexpected side effect in "orderMyReposByStars" computed property
src/components/HelloWorld.vue:84:14
return this.myRepos.sort((a, b) => a.stargazers_count < b.stargazers_count)
Run Code Online (Sandbox Code Playgroud)
HTML:
<div v-if="myRepos && myRepos.length > 0">
<h3>My Repos</h3>
<ul>
<li v-for="repo in orderMyReposByStars" v-bind:key="repo.id">
<div class="repo">
{{repo.name}}
<div class="pull-right">
<i class="fas fa-star"></i>
<span class="bold">{{repo.stargazers_count}}</span>
</div>
</div>
</li>
</ul>
</div>
Run Code Online (Sandbox Code Playgroud)
JS:
export default {
name: 'HelloWorld',
data () {
return {
myRepos: null, <-- THIS IS ULTIMATELY AN ARRAY OF OBJECTS
}
},
computed: {
orderMyReposByStars: function () {
return this.myRepos.sort((a, …
Run Code Online (Sandbox Code Playgroud) 我正在尝试编写测试来测试连接到mongo的方法,但我实际上并不想让mongo运行并实际建立连接以使我的测试成功通过.
这是我当前的测试,当我的mongo守护程序运行时,它是成功的.
describe('with a valid mongo string parameter', function() {
it('should return a rejected promise', function(done) {
var con = mongoFactory.getConnection('mongodb://localhost:27017');
expect(con).to.be.fulfilled;
done();
});
});
Run Code Online (Sandbox Code Playgroud)
mongoFactory.getConnection代码:
getConnection: function getConnection(connectionString) {
// do stuff here
// Initialize connection once
MongoClient.connect(connectionString, function(err, database) {
if (err) {
def.reject(err);
}
def.resolve(database);
});
return def.promise;
}
Run Code Online (Sandbox Code Playgroud) 我可以使用.p12密钥文件使用域服务授权的Google服务帐户.
我想使用JSON密钥文件而不是p12文件,但我无法弄清楚如何在使用JSON密钥时设置服务帐户ID.
如何使用JSON密钥文件将用户设置为模拟?
工作良好:
File p12File = new File(...);
GoogleCredential.Builder b = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY).setServiceAccountId(properties.getServiceAccountId())
.setServiceAccountPrivateKey(SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(),
new FileInputStream(p12File), "notasecret",
"privatekey", "notasecret"))
.setServiceAccountScopes(GOOGLE_SCOPE_LIST);
if (properties.getServiceAccountEmail() != null) {
b = b.setServiceAccountUser(properties.getServiceAccountEmail());
}
credential = b.build();
Run Code Online (Sandbox Code Playgroud)
不起作用:
String jsonKeyContents = "{\n" +
" \"type\": \"service_account\",\n" +
" \"project_id\": \"sxxxxxxx0\",\n" +
" \"private_key_id\": \"csxxxxxxxxxxxxxxxx\",\n" +
" \"private_key\": \"-----BEGIN PRIVATE " +
"KEY-----\\nMIIxxxxxxxxxxsTbwzsbw" +
"==\\n-----END PRIVATE KEY-----\\n\",\n" +
" \"client_email\": \"xxxxx@xxxxxx-123456.iam.gserviceaccount.com\",\n" +
" \"client_id\": \"1111111111111111111\",\n" +
" \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n" +
" \"token_uri\": \"https://accounts.google.com/o/oauth2/token\",\n" + …
Run Code Online (Sandbox Code Playgroud)