小编Vis*_*hal的帖子

如何使用aws弹性负载均衡器强行将http请求重定向到独立乘客的https?

我在我的应用程序中使用了独立乘客.目前我的应用程序在http和https上运行.我想将所有http请求重定向到https.我在我的应用程序中使用了负载均衡器.我读过这篇文章

https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/

https://www.phusionpassenger.com/library/config/standalone/intro.html#nginx-configuration-template

http://code.eklund.io/blog/2015/03/17/managing-rewrites-for-a-rails-app-on-heroku-with-nginx-plus-phusion-passenger/

我尝试了这两种方法

1)

 if ($http_x_forwarded_proto = "http") { 
            return 301 https://$host$request_uri; 
        }
Run Code Online (Sandbox Code Playgroud)

2)

if ($http_x_forwarded_proto != "https") {
      rewrite ^(.*)$ https://$server_name$REQUEST_URI permanent;
  }
Run Code Online (Sandbox Code Playgroud)

我以同样的方式尝试了所有过程.但每次进入无限循环时,在我开始乘客之前,实例会因为请求超时太多而终止自身并创建新实例.

我无法弄清楚,无论是弹性负载平衡器还是乘客配置问题.我想当我停止乘客和用户尝试访问应用程序.生成请求超时以及由于创建了新实例.我不确定.

提前致谢 :)

ruby-on-rails passenger nginx amazon-web-services elastic-load-balancer

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

经审核的Gem current_user_method无效

我在我的应用程序中使用Audited gem来跟踪用户日志.除了当前的用户跟踪,一切正常.

在我的情况下,我有2个模型:InstructorStudent.Instructor将是current_admin_user,我需要手动找到学生.

为了解决这个问题,我尝试current_user_method在初始化程序中覆盖并创建一个audited.rb文件,其中包含以下内容:

Audited.current_user_method = :current_admin_user
Run Code Online (Sandbox Code Playgroud)

这工作正常,但当我使用任何其他方法,如current_user_or_student...

Audited.current_user_method = :current_user_or_student
Run Code Online (Sandbox Code Playgroud)

application_controller.rb......

def current_user_or_student
  current_admin_user || InstructorStudent.find_by_id(id)
end
Run Code Online (Sandbox Code Playgroud)

它不会进入这种方法,甚至current_admin_user也不会存储在审计中.

为什么current_user_or_student在覆盖它时我的方法不被调用application_controller.rb

ruby-on-rails acts-as-audited

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

如何在Angular 2中打印Pdf

我有exf url的pdf文件的URL是"test.example.com/incoice/1/download?auth_token="some_token",当我访问此URL时,url将在浏览器中显示PDF.

现在我想用打印功能打开这个pdf,我的意思是用户不必按CTRL+P我想从我这边做这个.

我试过iframe,但它给了我错误的交叉起源.这是我使用的演示代码

//first try

 let _printIframe;
var iframe = _printIframe;
if (!_printIframe) {
    iframe = _printIframe = document.createElement('iframe');
    document.body.appendChild(iframe);

    iframe.style.display = 'none';
    iframe.id  = "printf";
    iframe.name = "printf";
    iframe.onload = function() {
      setTimeout(function() {
        iframe.focus();
        iframe.contentWindow.print();
      }, 1);
    };
  }

// second try 
   // SRC of pdf
iframe.src = "Some API URl " + "/download?access_token=" + 
this.authenticationService.currentTokenDetails.access_token;
let url = iframe.src + "&output=embed";

window.frames["printf"].focus();
window.frames["printf"].print();
var newWin = window.frames["printf"];
newWin.document.write('<body onload="window.print()">dddd</body>');
newWin.document.close();
Run Code Online (Sandbox Code Playgroud)

我在plunker中为print pdf创建了一个demo.http://embed.plnkr.co/WvaB9HZicxK6tC3OAUEw/在这个plunker我打开pdf在新窗口,但我想直接打印该pdf.我怎样才能做到这一点 …

javascript pdf angular

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

React - 如何在 react-select 中设置默认值

我在我的应用程序中使用了react-select来显示选择框。下面是我选择的代码。

<Select
       className="custom-form-control mb-2"
       name="organization_options"
       options={this.organizationOptions()}
       placeholder={false}
       onChange={this.handleChange.bind(this)}
       value={selectedValue === "" ? this.organizationOptions()[0] : selectedValue}
/>
Run Code Online (Sandbox Code Playgroud)

以下是我在选择框中已有的选项

0: {value: "62", label: "Dfdf"}
1: {value: "128", label: "Dfdfdsf"}
2: {value: "151", label: "Fgfdgdfh"}
3: {value: "121", label: "Hhhfas"}
4: {value: "55", label: "My Sensor_56"}
5: {value: "13", label: "New Org"}
6: {value: "44", label: "Org 2"}
7: {value: "148", label: "Testing App"}
Run Code Online (Sandbox Code Playgroud)

我有来自查询字符串的值,如 value="55",如果该值存在,我想在选择框中显示所选值。

我尝试了 2 种不同的方式,如下面的代码所示,

1)

selectedValue='55'
defaultValue={this.organizationOptions().find(op => {
   return op.value === selectedValue
})}
Run Code Online (Sandbox Code Playgroud)

2

defaultValue={{value: …
Run Code Online (Sandbox Code Playgroud)

reactjs react-select

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

Rails Active Storage - 如何将本地文件迁移到 s3 存储桶

早些时候我的文件上传到存储文件夹中。但现在我想在 s3 存储桶上上传图像。如何迁移 s3 存储桶上现有的本地数据?

我在这里找到了脚本https://www.stefanwiert.de/blog/2018/11/05/active-storage-migrate- Between-providers-from-local-to-amazon/ 但出现错误

NoMethodError(为 Active Storage 调用私有方法“open”

那么如何将本地数据迁移到s3存储桶呢?

有没有更简单的方法?

ruby-on-rails amazon-s3 rails-activestorage

6
推荐指数
2
解决办法
3676
查看次数

React-如何处理嵌套表格及其价值

我必须设置一种具有单个表格中嵌套值的表格基本上我需要将以下格式的数据发送到API

Payload: {"name": "The org name", "detail": "The org detail", "attributes": {"address": {"lines":[], "city":"", "state": "", "country": "India", "zip": ""}, "contacts":[{"name": "abc", "phone": "PH"}, {"name": "x", "phone": "PH"}] }}
Run Code Online (Sandbox Code Playgroud)

我使用react-bootstrap处理表单。

以下是我表格的当前代码

constructor(props) {
    super(props);
    this.state = this.getInitialState();
  }
  getInitialState() {
    const initialState = {
      organizationForm: {
        name: '',
        detail: '',
        type: 'org',
        attributes: {
          contacts: [{
            name: '',
            phone: ''
          }],
          address: {
            lines: [],
            city: '',
            state: '',
            country: '',
            zip: ''
          }
        }
      },
      errors: {}
    };

    return …
Run Code Online (Sandbox Code Playgroud)

reactjs

4
推荐指数
2
解决办法
2678
查看次数

React - onSelect 函数在 React Bootstrap 中不起作用

我在我的应用程序中使用了“react-bootstrap”。我使用了Tab Component。我想要选项卡组件的 onSelect 功能。

下面是我的组件代码

export default class Users extends Component {
  handleSelect() {
    console.log("Tab selected")    
  } 

  render() {
    return(
      <div className="welcome-wrap">
        <br />
        <div className="row">
          <h3>Users</h3>
          <Tabs defaultActiveKey={1} animation={false} id="user-role-tab">
            <Tab eventKey={1} title="Root Users" className="
            " onSelect={this.handleSelect()}>
              <RootUser/>
            </Tab>
            <Tab eventKey={2} title="Organization Users" onSelect={this.handleSelect()}>
              <OrganizationUser/>
            </Tab>
            <Tab eventKey={3} title="Business Users" onSelect={this.handleSelect()}>
              <BusinessUser/>
            </Tab>
          </Tabs>
        </div>
      </div>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)

它在加载组件时工作,但是当我单击任何选项卡时,不会调用该函数。我检查了如何在 react-bootstrap 中更改的选项卡上调用事件的解决方案,但它也不起作用。

reactjs react-bootstrap

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