小编Gok*_*l M的帖子

指定要部署在 Elastic Beanstalk 环境中的 git 分支代码

有什么方法可以指定要部署到 Elastic Beanstalk 环境的 git 分支代码吗?

假设,我有两个名为teststage 的git 分支,并且有一个名为test-env的 Elastic Beanstalk 环境。

现在,我将分支默认设置config.yml如下:

branch-defaults: 
  test:
    environment: test-env
    group_suffix: null
global:
  application_name: test
  default_ec2_keyname: abcde
  default_platform: Ruby 2.2 (Puma)
  default_region: us-west-2
  profile: eb-cli
  sc: git
Run Code Online (Sandbox Code Playgroud)

现在,我需要的是,如果我从阶段分支部署eb deploy test-env它应该自动从测试分支部署代码或者它应该抛出错误..

有什么办法可以做到。如果没有,请建议我一些其他的方法来做到这一点..

谢谢..

git ruby-on-rails amazon-web-services amazon-elastic-beanstalk

6
推荐指数
1
解决办法
1688
查看次数

读取一个句子,直到使用2-D char数组按下ENTER键

我需要逐字阅读一个句子,直到按下“ ENTER”键。我使用了do..while循环读取单词,直到按下ENTER键。请建议我一些检查ENTER键的条件(或)以其他方式读取类似的输入。

#include<iostream>
#include<string.h>
using namespace std;

int main(){

     char a[100][20]={'\0'};
     int i=0;

     do{
        cin>>a[i++];
     } while( \\ Enter key is not pressed );

     for(int j= 0 ; j < i ; j++)
        cout<< a[j] << " "; 
    return 0;
 }
Run Code Online (Sandbox Code Playgroud)

c++ arrays string words enter

5
推荐指数
2
解决办法
1万
查看次数

调用另一个控制器的方法

我有一个名为控制器ChildrenFatherMother,我需要调用的方法FatherController,并MotherControllerChildrenController.

我需要(通过一个JSON数据到两个控制器不能在同一请求)get_details从方法set_details的方法ChildrenController.我将根据某些条件调用任何控制器方法.

没有途径用于get_details在两个控制器的方法.我不需要任何帮助方法来编写.

我需要调用多个Controller的方法,而不是通过继承.

父亲控制器

class FatherController < ApplicationController

  def get_details(data)
    ##
    ## I need to do some operation with the 'data' received from children controller.
  end

end
Run Code Online (Sandbox Code Playgroud)

母亲控制器

class MotherController < ApplicationController

  def get_details(data)
    ##
    ## I need to do some operation with the 'data' received from children controller.
  end

end
Run Code Online (Sandbox Code Playgroud)

儿童控制器

class ChildrenController < …
Run Code Online (Sandbox Code Playgroud)

controller ruby-on-rails ruby-on-rails-4

5
推荐指数
1
解决办法
1万
查看次数

Rails - 使用 ActiveRecord::Enum 时出现 ArgumentError

我创建了一个Tester带有整数列的模型,tester_type并在模型中声明了 enum 变量。

class Tester < ApplicationRecord
  enum tester_type: { junior: 0, senior: 1, group: 2 }
end
Run Code Online (Sandbox Code Playgroud)

尝试为该模型创建/初始化对象时出现以下错误:

ArgumentError:您试图在模型“Tester”上定义一个名为“tester_type”的枚举,但这将生成一个类方法“group”,该方法已由 Active Record 定义。

所以,我尝试更改tester_type为,type_of_tester但它引发了相同的错误:

ArgumentError:您试图在模型“Tester”上定义一个名为“type_of_tester”的枚举,但这将生成一个类方法“group”,该方法已由 Active Record 定义。

我已经搜索了解决方案,我发现这个错误是ActiveRecord::Enum类中的一个常量ENUM_CONFLICT_MESSAGE,但是无法找到这个问题的原因。

请帮我。

谢谢。

enums activerecord ruby-on-rails ruby-on-rails-5

5
推荐指数
2
解决办法
3051
查看次数

查找字符串的所有可能排列

我有以下程序来查找字符串的所有可能的排列.

#include <stdio.h>

 /* Function to swap values at two pointers */
 void swap (char *x, char *y)
{
    char temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

/* Function to print permutations of string
   This function takes three parameters:
   1. String
   2. Starting index of the string
   3. Ending index of the string. */
void permute(char *a, int i, int n)
{
   int j;
   if (i == n)
       printf("%s\n", a);
   else
   {
       for (j = i; …
Run Code Online (Sandbox Code Playgroud)

c c++ arrays string algorithm

4
推荐指数
1
解决办法
889
查看次数

在部署中安装gem失败 - AWS Elastic Beanstalk

当我尝试在AWS Elastic Beanstalk(EB)环境中部署应用程序时,未安装本机gem.

EB-activity.log

  Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
  installing your bundle as root will break this application for all non-root
  users on this machine.
  Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
  fatal: Not a git repository (or any of the parent directories): .git
  fatal: Not a …
Run Code Online (Sandbox Code Playgroud)

deployment ruby-on-rails amazon-web-services amazon-elastic-beanstalk

3
推荐指数
1
解决办法
2616
查看次数

Rails:在JavaScript中捕获错误消息

我正在使用ajax创建属于特定主题的帖子,我在帖子索引页面中呈现表单.每个帖子都有很多标签,我也使用设计认证和CanCanCan授权.

我需要捕获帖子提交的错误消息并通过此JavaScript模板Create.js.erb在浏览器中显示自定义错误消息,而不是在帖子表单中.

以下是代码:

后控制器

class PostsController < ApplicationController
  load_and_authorize_resource
  before_action :set_post, only: [:show, :edit, :update, :destroy, :update_status]
  skip_before_action :verify_authenticity_token

  # GET /posts
  # GET /posts.json
  def index
    if params[:topic_id].present?
          @topic = Topic.find(params[:topic_id])
          @posts = @topic.posts.paginate(page: params[:page], per_page: 10)
      @post = @topic.posts.new
    else
      @posts = Post.eager_load(:topic, :user).paginate(page: params[:page], per_page: 10)
    end
    @tags =Tag.all
    end

  # GET /posts/1
  # GET /posts/1.json
  def show
      @tags = @posts.tags
  end

  def update_status
      current_user.posts<<(@posts)
  end

  # GET /posts/new
  def new
      @topic = Topic.find(params[:topic_id])
    @posts …
Run Code Online (Sandbox Code Playgroud)

javascript ruby ajax jquery ruby-on-rails

2
推荐指数
1
解决办法
3823
查看次数

对于循环变量范围

使用此示例:

arr = [1, 2, 3]

for elem in arr do
  puts elem
end

puts elem # => 3
Run Code Online (Sandbox Code Playgroud)

代码输出:

1
2
3
3
Run Code Online (Sandbox Code Playgroud)

elem包含循环外的值.为什么?循环外的范围是什么?

有人可以澄清吗?

ruby scope for-loop

1
推荐指数
1
解决办法
1108
查看次数

对发布的肯定 - MQTT

如何识别是否publishtopic被成功与否.有没有办法获得发布到主题的确认.

如果publish客户端(发布者/订阅者)之间的连接丢失如何处理它.

我不希望订阅者在收到pay_load后在发布端向特定主题发送确认.

这是我的红宝石代码:

假设,我已创建客户端(@client)并在双方配置.

发布

def publish_it
  @client.publish('test/hai', 'message')
  # Ack the publish
end
Run Code Online (Sandbox Code Playgroud)

订阅

@client.subscribe('test/#')

@client.get do |topic,message|
  puts "#{topic}: #{message}"
end
Run Code Online (Sandbox Code Playgroud)

ruby mqtt ruby-mqtt

1
推荐指数
1
解决办法
926
查看次数

查找并清除吐司(Toastr)

我有一个页面,其中可能toasts使用插件https://github.com/CodeSeven/toastr动态添加了多个页面。

单击该链接时,我在每个祝酒词上都有一个link(确定),我只需要关闭特定的(toast不是全部)toast可见的即可。

toastr.warning("You are warned. <br/> <a id='close-toastr'> Ok </a>", {
    tapToDismiss: false
    , timeOut: 0
    , extendedTimeOut: 0
    , allowHtml: true
    , preventDuplicates: true
    , preventOpenDuplicates: true
    , newestOnTop: true
});

$('body').on('click', 'a#close-toastr', function () 
    toastr.clear();
});
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,我使用了toastr.clear()清除所有吐司的方法。

谁能帮我识别一下toastOK” link并仅清除该吐司吗?

更新#1:

我尝试了@imjosh给出的答案,但是$(this).closest('.toast')找到了正确的吐司,但toastr.clear($(this).closest('.toast'));没有关闭任何吐司。

如果我将烤面包存储object在一个变量中,并将其作为参数传递给toastr.clear()它,那么它将起作用。但是,我不知道如何以这种方式处理多个吐司。

var toast = toastr.warning("You are warned. <br/> <a id='close-toastr'> Ok </a>", …
Run Code Online (Sandbox Code Playgroud)

javascript jquery angularjs toastr angular-toastr

1
推荐指数
2
解决办法
1万
查看次数