小编use*_*350的帖子

在设计之上滚动令牌auth mechanisim [Rails 4]

阿罗哈,

在发现Devise的'token_authenticatable已被折旧后,我现在正试图推出自己的解决方案,但是我认为我遇到了设计'sign_in方法的问题:

规格:

context "with an admin user" do
    before(:each) { @user = FactoryGirl.create(:user, account_type: 'admin') }
    it "should respond with a 200 status" do
        post :verify, "token"=> @user.authentication_token
        response.status.should eq(200)
    end
 end
Run Code Online (Sandbox Code Playgroud)

错误:

1) UsersController#verify with an admin user should respond with a 200 status
     Failure/Error: post :verify, "token"=> @user.authentication_token
     NoMethodError:
       undefined method `user' for nil:NilClass
     # ./app/controllers/application_controller.rb:24:in `authenticate_user_from_token!'
     # ./spec/controllers/users_controller_spec.rb:39:in `block (4 levels) in <top (required)>'
Run Code Online (Sandbox Code Playgroud)

application_controller.rb:

class ApplicationController < ActionController::Base
  # If there's a token present we're …
Run Code Online (Sandbox Code Playgroud)

authentication api ruby-on-rails devise ruby-on-rails-4

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

Rails 3.1,Postgres 9.1.4,hstore未知运算符错误

我正在尝试将hstore数据列添加到现有的STI模型中.

类似于Postgres HStore错误 - 未知运算符但据我所知,我已经安装了hstore扩展.我已经删除了数据库并从迁移重建它而没有错误,但规格仍然失败.

Mac OS X 10.8.2
Rails 3.1.10
psql (PostgreSQL) 9.1.4
Run Code Online (Sandbox Code Playgroud)

user.rb

has_many :targets

def complete_targets
  targets.where("data @> (:key => :value)", key: 'complete', value: 'true')
end
Run Code Online (Sandbox Code Playgroud)

targets.rb

belongs_to :user
serialize :data, ActiveRecord::Coders::Hstore
Run Code Online (Sandbox Code Playgroud)

setup_hstore迁移:

class SetupHstore < ActiveRecord::Migration
  def self.up
    execute "CREATE EXTENSION IF NOT EXISTS hstore"
  end

  def self.down
    execute "DROP EXTENSION IF EXISTS hstore"
  end
end
Run Code Online (Sandbox Code Playgroud)

添加数据列迁移:

class AddDataToRecords < ActiveRecord::Migration
  def change
    add_column :records, :data, :hstore
  end
end
Run Code Online (Sandbox Code Playgroud)

添加索引迁移:

class AddHstoreIndexes < ActiveRecord::Migration …
Run Code Online (Sandbox Code Playgroud)

postgresql ruby-on-rails hstore

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