小编sim*_*imo的帖子

FactoryGirl,为什么我已经注册或未初始化不变?

我正在尝试为我的模型做一个简单的测试Course,我写了这个工厂:

FactoryGirl.define do
  factory :course do
    name 'How to be happy ?'
    end
end
Run Code Online (Sandbox Code Playgroud)

course_spec.rb:

require "rspec"
require 'factory_girl_rails'
describe "When a course is created" do

  it "can't be deleted if any student is enrolled to it" do
    FactoryGirl.find_definitions
    course = FactoryGirl.build(:course)

    student= Student.create!
    course.students << student
    course.destroy
    course.name.should !=nil
  end
end
Run Code Online (Sandbox Code Playgroud)

但是,我达到了这条线

course = FactoryGirl.build(:course)
Run Code Online (Sandbox Code Playgroud)

我收到错误:

FactoryGirl::DuplicateDefinitionError: Factory already registered: course
Run Code Online (Sandbox Code Playgroud)

如果我在工厂评论:课程定义,我得到:

NameError: uninitialized constant Course
Run Code Online (Sandbox Code Playgroud)

有什么好主意吗?

这是我的Gem Envioronment:

RubyGems Environment:
RUBYGEMS VERSION: 1.8.10
RUBY VERSION: 1.9.3 …
Run Code Online (Sandbox Code Playgroud)

tdd ruby-on-rails-3 ruby-on-rails-3.1 factory-bot

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

为什么回收不起作用?

我们有一个桌面应用程序,我们有一个ListView,它ListView.ItemTemplate是一个扩展的KPageScrollViewerScrollViewer

虽然我们设定VirtualizingStackPanel.IsVirtualizing="True"VirtualizingStackPanel.VirtualizationMode="Recycling"

我们注意到KPageScrollViewer的构造函数(在其中ItemTemplate)总是在查看ListView中的项目时执行.

我们期望它将被创建4到5次,然后,相同的实例将用于查看数据,因为我们使用的是回收模式,但这不会发生,因此我们最终会得到越来越多的KPageScrollViewer实例创造..

是因为我们定制了ListView.ItemsPanel吗?

<ListView.ItemsPanel>
    <ItemsPanelTemplate >
        <p:KVirtualizingStackPanel IsItemsHost="True"
Run Code Online (Sandbox Code Playgroud)

有什么好主意吗?我想知道哪些原因会导致回收功能丢失?

<ListView  x:Class="KETAB.KStudio.Stage.PagesView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:p="clr-namespace:KETAB.KStudio.Stage"
    Name="PagesList" ScrollViewer.HorizontalScrollBarVisibility="Hidden" ScrollViewer.VerticalScrollBarVisibility="Hidden" 
    Loaded="instScroll_Loaded"
    AllowDrop="True" 
    MouseMove="PagesList_MouseMove"
    ScrollViewer.PanningMode="None"
    VirtualizingStackPanel.IsVirtualizing="True"
    VirtualizingStackPanel.CleanUpVirtualizedItem="PagesList_CleanUpVirtualizedItem"
    VirtualizingStackPanel.VirtualizationMode="Recycling"
    >

    <ListView.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary  Source="Resources/StageResources.xaml"/>
                <ResourceDictionary Source="/KETAB.KStudio.UserControls;component/ScrollViewerStyle.xaml" />
            </ResourceDictionary.MergedDictionaries>
            <SolidColorBrush  x:Key="{x:Static SystemColors.HighlightBrushKey}" Opacity="0.4" Color="Transparent" />
            <SolidColorBrush  x:Key="{x:Static SystemColors.ControlBrushKey}"  Opacity="0.4" Color="Transparent"  />
            <!--<p:PageWidthConverter x:Key="PageWidthConverter" />-->
            <p:PageWidthConverter x:Key="pageWidthConverter" />
            <p:PageHeightConverter x:Key="pageHeightConverter" />
            <Style  TargetType="{x:Type ListViewItem}">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type ListViewItem}">
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" SnapsToDevicePixels="{TemplateBinding …
Run Code Online (Sandbox Code Playgroud)

.net wpf scroll recycle

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

如何测试广播驱动程序?

我想知道是否有可能ShouldBroadcast在Laravel中进行测试?我的测试将触发实现的偶数ShouldBroadcast,但是,我注意到广播并未发生。

当然,广播事件本身就是在应用程序中进行的。

有没有人尝试过这种测试?

laravel laravel-5.1 laravel-5.2

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

will_paginate呈现空白结果

我已经安装了最后一个版本的will_paginate,我试图在我的视图中使用它,如下所示:

@courses = Course.paginate(:page => params[:page])
will_paginate @courses
Run Code Online (Sandbox Code Playgroud)

但是,我在视图中什么都没得到!任何的想法 ??

满足以下条件:

>> defined? WillPaginate
>> ActiveRecord::Base.respond_to? :paginate
Run Code Online (Sandbox Code Playgroud)

有什么我想念的吗?

ruby-on-rails will-paginate ruby-on-rails-3

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

rails 3.2,如何为HTTP动词put写路由,并在link_to中使用它?

我正在尝试写两个拒绝和批准行动的链接,但是,我不知道如何写出正确的路线,

我的路线.rb

put 'approve_class_room/:id(.:format)', :to => 'class_room_member_ships#approve'
put 'reject_class_room/:id(.:format)', :to => 'class_room_member_ships#reject'
Run Code Online (Sandbox Code Playgroud)

但是,在rake路线中,我得到:

PUT    /approve_class_room/:id(.:format) class_room_member_ships#approve
PUT    /reject_class_room/:id(.:format)  class_room_member_ships#reject
Run Code Online (Sandbox Code Playgroud)

那么,什么是正确的link_to路径?

我的链接是

= link_to 'approve', approve_class_room_path
Run Code Online (Sandbox Code Playgroud)

它不会工作,我得到:

undefined local variable or method `approve_class_room_path'
Run Code Online (Sandbox Code Playgroud)

ps:我正在尝试让link_to使用AJAX工作,在同一页面上进行批准,AM我是否正确?什么是link_to路径?

有什么好主意吗?

routes ruby-on-rails-3

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

为什么CSS在发送HTML电子邮件时不起作用?

当我在heroku使用SendGrid服务时,我注意到当我发送基于HTML的电子邮件时,CSS没有效果,任何人都可以告诉我什么可能是错的?

我试图将它作为html.haml,html.erb发送,但两者都不起作用,尽管在发送的电子邮件中正确查看了图像.

任何的想法 ?

css heroku html-email sendgrid ruby-on-rails-3

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

如何将pry与RubyMine IRB控制台集成?

如何使用pry调试rails应用程序而不是RubyMine IRB控制台?我应该在我的gemfile中添加pry-rails和pry吗?

rubymine ruby-on-rails-3 pry

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

如何在渲染视图上测试文本?

这是我的测试:

require "rspec"

describe HomeController do
  render_views

  it "should renders the home" do
    get :home
    response.should render_template("home")
    response.should include_text("Simulate Circuits Online")
  end

end
Run Code Online (Sandbox Code Playgroud)

但是,我得到了:

1) HomeController should renders the home
     Failure/Error: response.should include_text("Some text to be test ..")
     NoMethodError:
       undefined method `include_text' for #<RSpec::Core::ExampleGroup::Nested_1:0xd429a0c>
     # ./spec/controllers/home_controller_spec.rb:9:in `block (2 levels) in <top (required)>'
     # (eval):6:in `block in fork'
     # (eval):6:in `fork'
     # (eval):6:in `fork'
Run Code Online (Sandbox Code Playgroud)

那么,测试所呈现文本的正确方法是什么?

编辑 如果我尝试 response.should have_content("My text ..")

我明白了

1) HomeController should renders the home
     Failure/Error: response.should have_content("My …
Run Code Online (Sandbox Code Playgroud)

rspec rspec2 ruby-on-rails-3.2

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

客户端数据压缩/解压缩?

我正在寻找字符串压缩/解压缩算法的 JavaScript 实现,其中数据在客户端创建并存储在 HTML 表单内的隐藏字段中。

我读到了有关gzip 的内容,但它会压缩数据服务器端,而在我的情况下,我想在客户端压缩它,将其发送到服务器,或从服务器接收它以在客户端再次解压缩。

我发现了这个基于LZFjs的LZF 压缩示例,但它将生成需要处理并存储在隐藏表单字段中的二进制数据,并且它适用于文件而不是纯数据。

关于高效的纯数据客户端数据压缩/解压缩的建议?

javascript compression gzip

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

该应用程序未在观察者中列出

虽然phenix服务器正常启动,但我在观察者的应用程序列表中看不到它。

我所做的是:

elixir -S mix phoenix.server
Run Code Online (Sandbox Code Playgroud)

并且,它是另一个终端:

iMac:~ Apple$ iex
Erlang/OTP 18 [erts-7.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.2.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :observer.start
:ok
Run Code Online (Sandbox Code Playgroud)

这是我的应用程序的启动方式:

defmodule Rumbl do
  use Application

  # See http://elixir-lang.org/docs/stable/elixir/Application.html
  # for more information on OTP Applications
  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      # Start the endpoint when the application starts
      supervisor(Rumbl.Endpoint, []),
      # Start the Ecto repository
      supervisor(Rumbl.Repo, []), …
Run Code Online (Sandbox Code Playgroud)

elixir phoenix-framework

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