小编Eri*_*win的帖子

如何在rails控制台中使用FactoryGirl中的工厂

我在开发环境中使用rails控制台,我想使用工厂.我怎样才能访问它们?

我试过require "FactoryGirl"哪个回归

1.9.3p393 :301 > require "FactoryGirl"
LoadError: cannot load such file -- FactoryGirl
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails factory-bot

85
推荐指数
4
解决办法
3万
查看次数

jsx表忽略换行符

我正在尝试使用多行字符串创建一个表,但我的表格未正确格式化该字符串.这是jsx:

<td>
  {arr.join('\n')}
</td>
Run Code Online (Sandbox Code Playgroud)

这里是相应的html:

<td data-reactid=".xyz">Line 1
Line 2
Line 3
Line 4</td>
Run Code Online (Sandbox Code Playgroud)

但在浏览器中它看起来像:

在此输入图像描述

发生了什么,我如何让我的新线出现?

javascript reactjs react-jsx

16
推荐指数
3
解决办法
2万
查看次数

重新加载不在rspec中工作的对象

我试图用以下代码测试控制器方法:

it "should set an approved_at date and email the campaign's client" do
  @campaign = Campaign.create(valid_attributes)

  post :approve, id: @campaign.id.to_s

  @campaign.reload
  @campaign.approved_at.should_not be(nil)
end
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此测试时,我收到以下错误:

 Failure/Error: @campaign.reload
 ActiveRecord::RecordNotFound:
   Couldn't find Campaign without an ID
Run Code Online (Sandbox Code Playgroud)

当我在rails控制台中运行类似的行时,重新加载工作并且值设置为我需要它.当我在rspec测试中运行代码时,为什么不重新加载?

activerecord rspec ruby-on-rails

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

如何查看已删除分支的git历史记录(使用git flow)

我用git flow创建了两个分支git flow feature start <feature name>.我不记得我是否完蛋了

  1. git flow feature finish在两个分支上使用,
  2. 将分支合并A到分支B,删除分支A,然后git flow feature finish从分支运行B,或
  3. 合并分支Bdevelopgit flow feature finish再合并分支Adevelopgit merge,解决合并冲突,然后删除分支Agit branch -d <branch name>

使用我能找到git reflog的最后一个分支跟踪Ae553bf0在系列中:

e553bf0 HEAD@{40}: checkout: moving from feature/a to develop
6b30050 HEAD@{41}: checkout: moving from develop to feature/a
e553bf0 HEAD@{42}: …
Run Code Online (Sandbox Code Playgroud)

git git-flow

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

Git重置不起作用

我做了一个提交,拉取并合并了一些更改,然后进行了第二次提交.当我想回到第一次提交时,我运行了命令

git reset --hard <sha hash>
Run Code Online (Sandbox Code Playgroud)

虽然响应是"HEAD现在位于<sha hash>",但我的代码看起来就像我运行该命令之前一样.通常,它会改变我以前的状态,但看起来有些东西不能正常工作.在重置头之前,是否需要运行不同的命令才能取消合并?


额外信息

我跑的git status时候说:

app/assets/images/.DS_Store.orig未跟踪

我可以添加它.

git reflog我所知,在我提交hash1之前(我认为"在合并之前").拉有一个sha hash2(git log没有显示).当我挖掘hash1和hash2时,我看到了我所做的更改,并且可以从中重建我的原始代码.不过,这似乎很奇怪.如果我尝试git reset其中任何一个,我无法在合并之前获取我的代码.

git git-reset

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

在rails应用程序中更改ActiveRecord :: Base.inheritance_column

我想使用除了以外的列使用单表继承type.根据Rails文档 - http://api.rubyonrails.org/classes/ActiveRecord/Base.html,我可以通过修改来做到这一点ActiveRecord::Base.inheritance_column.我怎样才能做到这一点?

activerecord ruby-on-rails single-table-inheritance

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

找不到FileMerge(opendiff工具),但我安装了xcode 4.6

当我尝试将FileMerge作为Opendiff的GUI运行时,我收到一个错误:

$ git mergetool -t opendiff
Merging:
Gemfile
Gemfile.lock
...

Normal merge conflict for 'Gemfile':
  {local}: modified file
  {remote}: modified file
Hit return to start merge resolution tool (opendiff): 
2013-12-26 20:00:20.248 opendiff[22367:e07] Couldn't find FileMerge
Gemfile seems unchanged.
Was the merge successful? [y/n] ^C
$
Run Code Online (Sandbox Code Playgroud)

我已经为Xcode安装了XCode 4.6.3和命令行工具2013年4月.我正在运行OSX 10.7.5

我尝试过以下两个链接的解决方案但没有成功:

与opendiff的git diff给出"无法启动FileMerge"错误

Xcode 4.3安装后,filemerge仍然可用吗?

当我去的时候,Xcode -> Open Developer Tool我没有FileMerge在选项列表中看到.这里有一个More Developer Tools链接:https://developer.apple.com/downloads/index.action?name = for%20Xcode%20-

我如何让FileMerge工作?

git macos xcode filemerge

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

"您需要提供至少一次验证",但存在Rails验证

我有以下验证:

class Event < ActiveRecord::Base
  attr_accessible :starts, :ends

  validates :no_multi_day_events

  private
    def no_multi_day_events
      if (ends.day != starts.day)
        errors.add(:ends, "No multi-day events")
      end
    end
end
Run Code Online (Sandbox Code Playgroud)

但是,当我尝试使用此文本加载页面时,出现错误: You need to supply at least one validation

我如何提供验证?

validation ruby-on-rails

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

当我将多行指令粘贴到其中时,Rails控制台启动"显示所有573种可能性?(y或n)"对话框

我将以下代码片段从我的文本编辑器复制到我的rails控制台:

request = Typhoeus::Request.new(
"https://track.customer.io/api/v1/customers/4", 
ssl_verifypeer: false,
method: :put,
headers: {
    "Content-Type" => "application/json",
    "User-Agent" => "#{Rails.configuration.customerio[:site_id]}:#{Rails.configuration.customerio[:api_key]}"},
body: '{
"email":"first@last.com", 
"name":"Name is here",
"id":"4",
"created_at":"#{Time.now}"}')
Run Code Online (Sandbox Code Playgroud)

当我将它全部复制为一行时:

request = Typhoeus::Request.new("https://track.customer.io/api/v1/customers/4", ssl_verifypeer: false,method: :put,headers: {"Content-Type" => "application/json","User-Agent" => "#{Rails.configuration.customerio[:site_id]}:#{Rails.configuration.customerio[:api_key]}"},body: '{"email":"first@last.com", "name":"Name is here","id":"4","created_at":"#{Time.now}"}')
Run Code Online (Sandbox Code Playgroud)

然后控制台返回标准响应:

 => #<Typhoeus::Request:0x00000101c517a8 @base_url="https://track.customer.io/api/v1/customers/4", @original_options=...
Run Code Online (Sandbox Code Playgroud)

但是,如果我逐行复制它(就像我在第一个代码片段中所做的那样),我会收到一个奇怪的错误.控制台询问我是否要显示所有可能性,就像我正在搜索目录或在粘贴中途进行搜索查询一样.看看这个:

1.9.3p393 :091 > request = Typhoeus::Request.new(
1.9.3p393 :092 >     "https://track.customer.io/api/v1/customers/4", 
1.9.3p393 :093 >     ssl_verifypeer: false,
1.9.3p393 :094 >     method: :put,
1.9.3p393 :095 >     headers: {
1.9.3p393 :096 >
Display all 573 possibilities? (y …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails

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

我应该如何升级我的Java编译器

当我跑步时,$ javac Simulator.java我得到以下警告:

warning: ./particle_simulator/Atom.class: major version 51 is newer than 50, the highest major version supported by this compiler.

我不知道为什么我突然得到这个警告,因为我没有对我的代码进行实质性更改.不过,我如何升级我的Java编译器?

我正在运行Mac OSX 10.7.5,我的Java版本如下:

java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)
Run Code Online (Sandbox Code Playgroud)

java compiler-construction macos

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