小编Spi*_*ion的帖子

Heroku postgresql数据库名称

这是我必须找到heroku数据库名称的命令:

$ heroku config | grep POSTGRESQL
Run Code Online (Sandbox Code Playgroud)

我得到的结果类似于:

HEROKU_POSTGRESQL_NAVY_URL: postgres://wxjwilh:tKDSwUlfZ8Da@fr6-84-24-28-19.compute-1.amazonaws.com:52/d14grmkt
Run Code Online (Sandbox Code Playgroud)

这个输出的哪一部分是我可以使用命令的数据库名称:

$ heroku pg:reset <DATABASE>
Run Code Online (Sandbox Code Playgroud)

我尝试使用整个网址,但得到了无效的参数错误.

postgresql heroku

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

git merge之后源和目标分支会发生什么?

当我运行git checkout branch1然后git merge branch2合并两个分支时,看起来像branch2只是覆盖branch1.这应该发生吗?

编辑:

合并前

  • branch1 = readme.txt(Hello World!)
  • branch2 = readme.txt(Hello 2!)

合并后

  • branch1 = readme.txt(Hello 2!)

tbh,我不确定合并在技术上应该做什么.

git

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

如何在此angularjs设计库身份验证服务上存储和设置用户?或者它已经完成了吗?

我在客户端上使用cloudspace angularjs-devise库.当我尝试登录/注册时,我在chrome js控制台中看到了普通用户对象的200 ok响应.刷新页面似乎丢失了这些信息,即使我假设服务会在某些时候存储它,因为它也有logout和currentUser方法. https://github.com/cloudspace/angular_devise

我的问题是:

1)这项服务是否实际存储了用户,如果是,如何(即使用cookies或localstorage或内存)?

2)如果服务没有存储用户,我如何将这些信息存储在自定义cookie/localstorage中,更重要的是将用户设置为服务,以便可以使用服务"isauthenticated"和"currentuser"方法?

部分图书馆自述文件说明

只需将Devise注册为模块的依赖项即可.然后,Auth服务将可供使用.

angular.module('myModule', ['Devise']).
    config(function(AuthProvider) {
        // Configure Auth service with AuthProvider
    }).
    controller('myCtrl', function(Auth) {
        // Use your configured Auth service.
    }); 
Run Code Online (Sandbox Code Playgroud)

Auth.login(creds):使用Auth.login()对服务器进行身份验证.请记住,凭据以明文形式发送; 使用SSL连接来保护它们.creds是一个对象,它应包含对服务器进行身份验证所需的任何凭据.Auth.login()将返回一个将解析为登录用户的promise.请参阅AuthProvider.parse()以将用户解析为可用对象.

angular.module('myModule', ['Devise']).
    controller('myCtrl', function(Auth) {
        var credentials = {
            email: 'user@domain.com',
            password: 'password1'
        };

        Auth.login(credentials).then(function(user) {
            console.log(user); // => {id: 1, ect: '...'}
        }, function(error) {
            // Authentication failed...
        });
    });
Run Code Online (Sandbox Code Playgroud)

我的部分代码:

main.js

var myApp = angular.module('mail_app', ['ngRoute', 'ngResource', 'Devise']);

myApp.config(function($routeProvider, $locationProvider, $httpProvider, AuthProvider) {
    console.log("in router") …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise angularjs

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

Ruby - 除非值为真,否则返回假,在这种情况下返回值

如果a = false并且b = 2是否有一种简洁的方法来实现这一点?使用只return a unless b返回 '​​nil' 而不是 '2'。

我有

def checkit
  return a unless b
  b
end
Run Code Online (Sandbox Code Playgroud)

这个语句会调用 b 两次吗?

一个真实的案例是:

def current_user
  @current_user ||= authenticate_user
end

def authenticate_user
    head :unauthorized unless authenticate_from_cookie 
end

def authenticate_from_cookie
  .
  if user && secure_compare(user.cookie, cookie)
    return user
  else
    return nil
  end
end
Run Code Online (Sandbox Code Playgroud)

ruby return conditional-statements

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

如何使用rails secure_compare?

我努力了

line:60  mv = ActiveSupport::MessageVerifier.new
         return nil unless mv.secure_compare(a, b)
Run Code Online (Sandbox Code Playgroud)

这给出了错误

ArgumentError - wrong number of arguments (0 for 1..2):
activesupport (4.0.3) lib/active_support/message_verifier.rb:29:in `initialize'
app/controllers/application_controller.rb:60:in `new'
Run Code Online (Sandbox Code Playgroud)

http://apidock.com/rails/ActiveSupport/MessageVerifier/secure_compare

编辑

主动支持方法是私有的,因此我只是将该方法直接复制到应用程序控制器中。

   def secure_compare(a, b)
    return false unless a.bytesize == b.bytesize

    l = a.unpack "C#{a.bytesize}"

    res = 0
    b.each_byte { |byte| res |= byte ^ l.shift }
    res == 0
  end
Run Code Online (Sandbox Code Playgroud)

这样做或使用此实现是否存在任何明显的安全问题?

security ruby-on-rails

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

设计管理员角色:PG ::错误:错误:关系"管理员"已存在

在成功配置设备配置后,我现在尝试添加Admin角色以准备使用rails_admin.

我遵循这些说明(https://github.com/plataformatec/devise/wiki/How-To:-Add-an-Admin-role)来添加管理角色以进行设计,即使生成的迁移看起来完全不同于说明.然后我运行"bundle exec rake db:migrate"只是为了得到错误:

PG::Error: ERROR:  relation "admins" already exists
Run Code Online (Sandbox Code Playgroud)

此时我还没有尝试安装rails_admin,因为我想让设备先完全工作.

有什么想法,为什么我以前没有管理员模型时出现此错误?

postgresql ruby-on-rails devise

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

如何在Rails/Angularjs html5模式中删除重定向

在使用带有rails的html 5模式时,如何在每次用户刷新angularjs页面时避免性能下降?我正在使用Angularjs html5模式Ruby on Rails路由重定向.使用我的设置,如果我http://localhost:3000/users立即访问该网址http://localhost:3000/?goto=users,然后重定向到http://localhost:3000/users.使用html5模式时,我该怎么做才能避免这种性质的重定向?

Rails路由

myApp::Application.routes.draw do
 namespace :api, defaults: {format: :json} do
   namespace :v1 do
    resources :users
   end
 end

# Re-route all angular requests to the angular router
get "/*path" => redirect("/?goto=%{path}")
root to: 'application#home'
Run Code Online (Sandbox Code Playgroud)

结束

角度路线

myApp.config(function($routeProvider, $locationProvider, $httpProvider) {
    $httpProvider.defaults.headers.common['X-CSRF-Token'] = 
    $('meta[name=csrf-token]').attr('content');
    $routeProvider.
        when('/', {
            templateUrl: '../assets/mainIndex.html',            
            controller: 'MainController',
            redirectTo:
                function(current, path, search){
                  if(search.goto){
                    // if we were passed in a search param, and it has a path
                    // to …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails angularjs

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

这个设计配置有什么作用?

我想将设计限制为来自互联网的 api 上的 json 请求。它有什么作用?

# config/initializers/devise.rb

config.http_authenticatable_on_xhr = false
config.navigational_formats = ["*/", :html, :json]
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise

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

强制单选按钮显示内联

我正在使用引导程序通过单选按钮设置表单样式。

不幸的是,display:inline没有使表单上的单选按钮内联。都不是将display:inline移入CSS。

<div class="row">
  <div class="span6 offset3">   
    <div style="display:inline">
      <%= f.label "status_open", "Open" %>
      <%= f.radio_button :status, 'Open' %> <br />
      <%= f.label "status_active",  "Active" %>
      <%= f.radio_button :status, 'Active' %> <br />
      <%= f.label "status_closed",  "Closed" %>
      <%= f.radio_button :status, 'Closed' %> <br />
      <%= f.label "status_matched", "Matched" %>
      <%= f.radio_button :status, 'Matched' %> <br />   
    </div>      
    <%= f.submit "Submit", class: "btn btn-large btn-primary" %>
    <% end %>
  </div>
</div>
Run Code Online (Sandbox Code Playgroud)

资源:

<div class="row">
<div class="span6 offset3">
<form accept-charset="UTF-8" action="/books" …
Run Code Online (Sandbox Code Playgroud)

html ruby-on-rails-3 twitter-bootstrap

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

rails g controller没有不必要的文件

我可以在控制器目录中创建一个控制器(通过创建文件+"_controller.rb"手动创建),还是必须运行生成控制器?我不需要额外的文件,但担心如果我不使用rails g,可能会在以后发生某些事情

ruby-on-rails

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

太阳黑子有什么区别:solr:run和sunspot:solr:start?

运行太阳黑子:solr:start引发错误

"在i386-mingw32上不支持此命令.使用rake sunspot:solr:run在前台运行Solr."

运行太阳黑子:solr:运行只是挂起.在"前景"中运行什么意味着什么?

编辑

如何运行solr:run和rails s?

solr ruby-on-rails sunspot

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

如何编写看似只读属性的内容?

在System.Exception基类中,有以下属性(如专业书#5.0中所述):

public virtual string Message { get; }

这看起来像只读属性或没有正文的常规属性.无论哪种方式,我都无法自己复制上面的代码.

编辑:

如果这描述了常规属性,则编译器会抱怨get没有正文.

c#

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