小编Ayd*_*kov的帖子

在rspec中指定什么意思

这行代码有什么作用?

assigns(:articles).should eq([article])
Run Code Online (Sandbox Code Playgroud)

在下面的rspec中

  describe "GET #index" do
    it "populates an array of articles" do
      article = Factory(:article)
      get :index
      assigns(:articles).should eq([article])
    end

    it "renders the :index view" do
      get :index
      response.should render_template :index
    end
  end
Run Code Online (Sandbox Code Playgroud)

bdd rspec ruby-on-rails

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

Resque作业,如何停止运行作业

我的Resque工人班

class WebWorker

  @queue = :jobs_queue

  def self.perform(id)
  //bunch of code here
  end
end
Run Code Online (Sandbox Code Playgroud)

我从队列中删除了这样的某个工作

Resque.dequeue(WebWorker,id)
Run Code Online (Sandbox Code Playgroud)

但是我想停止运行并重新启动,我该怎么做?

ruby-on-rails delayed-job resque

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

Devise/Capybara模棱两可的比赛

我正在使用devise来创建一个注册向导,但是capybara(2.0.2)会加注

Feature: Signing up
    In order to be attributed for my work
    As a user
    I want to be able to sign u

Scenario: Signing up
    Given I am on the homepage
    When I follow "Sign up"
    And I fill in "Email" with "user@ticketee.com"
    And I fill in "Password" with "password"
    Ambiguous match, found 2 elements matching field "Password" (Capybara::Ambiguous)
./features/step_definitions/web_steps.rb:10:in `/^(?:|I )fill in "([^"]*)" with "([^"]*)"$/'
features/signing_up.feature:10:in `And I fill in "Password" with "password"'
    And I fill in "Password …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails cucumber devise capybara

9
推荐指数
2
解决办法
9434
查看次数

切换到黄瓜,水豚的弹出窗口

在RSpec我可以使用这样的代码切换到弹出窗口,链接,我怎么能在Cucumber步骤中做这样的事情?

login_window = page.driver.find_window('PPA_identity_window')
    main_window = page.driver.find_window('')

    # We use this to execute the next instructions in the popup window
    page.within_window(login_window) do
      #Normally fill in the form and log in
      fill_in 'email', :with => "<your paypal sandbox username>"
      fill_in 'password', :with => "<your paypal sandbox password>"
      click_button 'Log In'
    end
Run Code Online (Sandbox Code Playgroud)

ruby popupwindow capybara

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

具有类型'const CompareVPtrs'的表达式将丢失一些const-volatile限定符以便调用

我在C++中实现十五个益智控制台游戏,引发了以下错误

Error   4   error C3848: expression having type 'const CompareVPtrs' would lose some const-volatile qualifiers in order to call 'bool CompareVPtrs::operator ()(Vertex *,Vertex *)' c:\program files\microsoft visual studio 11.0\vc\include\xfunctional    324 1   puzzle15
Run Code Online (Sandbox Code Playgroud)

这是我的结构

struct CompareVPtrs: public binary_function<Vertex*, Vertex*, bool>
{
    bool operator()( Vertex *lhs, Vertex *rhs)
    {
        return equal((int *)lhs->state, (int *)lhs->state+16,
            (int *)rhs->state);
    }
}
CompareVP;
Run Code Online (Sandbox Code Playgroud)

完整的游戏源代码 https://gist.github.com/sunloverz/7338003

c++ stl

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

在golang中获取会话值

我的rails应用程序使用会话存储用户凭据以进行授权.尝试在Go代码中登录并执行一些操作(需要用户会话).我应该在登录时检索用户会话并传递给下一个请求吗?我该怎么处理?

session http go ruby-on-rails-4

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

具有多个组件的延迟加载功能模块在 angular 6 中不起作用

我有一个customer带有customer-routing模块的模块:

const routes: Routes = [
  {
    path: '', component: CustomerComponent,
    children: [
      { path: 'edit', component: EditCustomerComponent }
    ]
  }
];
Run Code Online (Sandbox Code Playgroud)

这是我的app-routing模块:

const routes: Routes = [
  { path: 'customers/:id', loadChildren: './customer/customer.module#CustomerModule' },
  { path: 'login', component: LoginComponent}
];
Run Code Online (Sandbox Code Playgroud)

但是当我遵循这样的路径时,customers/3/edit它告诉我总是CustomerComponent不会EditCustomerComponent

也许延迟加载不起作用?

PS:我使用的是 angular 6.1.0

更新:我的客户模块

import {ReactiveFormsModule} from '@angular/forms';
import {CustomerComponent} from './customer.component';
import {EditCustomerComponent} from './edit-customer.component';

@NgModule({
  imports: [
    CommonModule,
    CustomerRoutingModule,
    ReactiveFormsModule
  ],
  declarations: [CustomerComponent, …
Run Code Online (Sandbox Code Playgroud)

angular angular6

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

使用 Yard 记录 Rails 项目

我正在使用 Yard 生成文档,但找不到任何关于 ruby​​ on rails 项目的示例文档。我在rubydoc.info上只找到了简短的入门教程和一些 github 项目,但根本没有记录它们。请有人告诉我如何正确记录控制器(带动作)、模型、rails 项目的路线

例如我有这样的控制器:

class ArticlesController < ApplicationController
  before_filter :authenticate_user!, except: [:show]
  before_filter :restrict_user, only: [:edit, :update]

  def index
    @articles = current_user.articles.sort_by_rating.
        paginate(:page => params[:page],
                 per_page: 5)
  end

  def new
    @user = User.find(params[:user_id])
    @article = @user.articles.build
  end

  def create
    @user = User.find(params[:user_id])
    @article = @user.articles.build(params[:article])

    if @article.save
      redirect_to  @article, notice: 'Article was successfully created.'
    else
      render action: "new"
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

和一个用户模型:

class User < ActiveRecord::Base
  # Include default …
Run Code Online (Sandbox Code Playgroud)

documentation ruby-on-rails yard

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

如何填充设计用户

我想使用faker和populator gems用虚假数据填充数据库.使用Devise生成模型用户.

这是我的rake文件

namespace :db do
  desc "Fill database with sample data"
  task populate: :environment do
    [User, Article].each(&:delete_all)
    password = "password"

    User.populate 20 do |user|
      user.name = Faker::Name.name
      user.email = Faker::Internet.email
      user.password = password
      user.password_confirmation = password
      Article.populate 5 do |article|
        article.user_id = user.id
        article.title = Populator.words(1..3).titleize
        article.content = Populator.sentences(2..10)
        article.created_at = 2.years.ago..Time.now
      end
    end

  end
end
Run Code Online (Sandbox Code Playgroud)

当我运行rake db:populate引发以下内容

rake aborted!
undefined method `password=' for #<Populator::Record:0xa179d14>
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/record.rb:64:in `method_missing'
    /home/sunloverz/RubymineProjects/socialnews/lib/tasks/sample_date.rake:10:in `block (3 levels) in <top (required)>'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:53:in `call'
    /home/sunloverz/.rvm/gems/ruby-1.9.3-p385/gems/populator-1.0.0/lib/populator/factory.rb:53:in `block in …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails devise

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

带有输入上方标签的内联引导程序表单

如何在与其他文本字段相同的级别上向下移动搜索按钮?

在此输入图像描述

  <form>
       <div class="col-md-3 form-group">
         <label for="search">Title</label>
         <input type="text" name="search" id="search" class="form-control" />
       </div>
       <div class="col-md-2 form-group">
         <label for="created_at_gt">Created at from</label>
         <input type="text" name="created_at_gt" id="created_at_gt" class="form-control" />
       </div>
       <div class="col-md-2 form-group">
         <label for="created_at_lt">To</label>
         <input type="text" name="created_at_lt" id="created_at_lt" class="form-control" />
       </div>
       <div class="row align-center">
         <input type="submit" value="search" class="btn btn-primary" />
        </div>
    </form>
Run Code Online (Sandbox Code Playgroud)

html css twitter-bootstrap-3

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