小编Tho*_*ann的帖子

使用工厂女孩创建HABTM协会

我现在已经尝试了几个小时让工厂女工创建两个工厂 - 一个用于用户,一个用于组织.

但我似乎不明白如何在工厂中反映'has_and_belongs_to_many'关系,一旦我尝试创建组织并将其与管理员用户关联,我会遇到各种错误消息(取决于我使用的方法) ).我的模型似乎工作正常,我的种子文件填充dev DB并创建所有关联.

现在我的文件看起来像这样:

用户工厂

FactoryGirl.define do

  factory :user do
    email 'example@example.com'
    password 'password'
    password_confirmation 'password'
    after(:create) {|user| user.add_role(:user)}

    factory :owner do
      after(:create) {|user| user.add_role(:owner)}
    end

    factory :admin do
      after(:create) {|user| user.add_role(:admin)}
    end

    factory :superadmin do
      after(:create) {|user| user.add_role(:superadmin)}
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

组织工厂

FactoryGirl.define do

  factory :organization do |f|
    f.name "example"
    f.website "www.aquarterit.com"
    f.association :users, :factory => :admin
  end
end
Run Code Online (Sandbox Code Playgroud)

在我的规格中我测试了这个:

describe Organization do


  it "has a valid factory" do
    FactoryGirl.create(:organization).should be_valid
  end

  it "is invalid without …
Run Code Online (Sandbox Code Playgroud)

rspec ruby-on-rails factory-bot

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

酿酒医生发出警告

当我跑啤酒医生时,我会发出大量警告.所以我继续,清理现有的安装并从头开始.

现在我仍然收到一些警告:

    Warning: "config" scripts exist outside your system or Homebrew directories.
`./configure` scripts often look for *-config scripts to determine if
software packages are installed, and what additional flags to use when
compiling and linking.

Having additional scripts in your path can confuse software installed via
Homebrew if the config script overrides a system or Homebrew provided
script of the same name. We found the following "config" scripts:

    /opt/sm/pkg/active/bin/curl-config
    /opt/sm/pkg/active/bin/ncurses5-config
    /opt/sm/pkg/active/bin/ncursesw5-config
    /opt/sm/pkg/active/bin/pkg-config
    /opt/sm/pkg/active/bin/xml2-config
    /opt/sm/pkg/active/bin/xslt-config
Warning: You have a non-Homebrew …
Run Code Online (Sandbox Code Playgroud)

homebrew

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

.field_with_errors混淆了引导程式的表单

我使用bootstrap 3的网格系统来布局一个简单的注册表单.但是,如果Rails中的验证失败,添加了类"field_with_errors"的div会弄乱我的布局.

以下是我的表单中的一行通常如下所示:

<div class="form-group">
    <label class="col-xs-2 control-label" for="user_secondary_email">Secondary email</label>
    <div class="col-xs-4">
    <input class="form-control" id="user_secondary_email" name="user[secondary_email]" type="text" />
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

验证失败时,当前应用的样式如下所示:

<div class="form-group">
    <div class="field_with_errors"><label class="col-xs-2 control-label" for="user_primary_email">Primary email</label></div>
    <div class="col-xs-4">
        <div class="field_with_errors"><input class="form-control" id="user_primary_email" name="user[primary_email]" type="text" value="" /></div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我做了一些研究,据我所知,这是代码应该是这样的:

<div class="form-group has-error">
        <label class="col-xs-2 control-label" for="user_secondary_number">Secondary number</label>
        <div class="col-xs-4">
            <input class="form-control" id="user_secondary_number" name="user[secondary_number]" type="text" />
        </div>
   </div>
Run Code Online (Sandbox Code Playgroud)

我不明白的是如何让应用程序将其他类添加到正确的html标记中?

任何帮助表示赞赏!

css ruby-on-rails twitter-bootstrap

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

无法安装pg gem

我花了好几个小时试图找出它为什么不起作用后终于设法得到'pg'宝石安装...

最后我进入了sudo env ARCHFLAGS="-arch x86_64" gem install pg -v 0.12.2 -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config一个像魅力一样的工作.但是现在我尝试捆绑时仍然有同样的错误 - 所以我猜我没有真正解决问题?无论如何,这bundle install是在说什么:

 Installing pg (0.12.2) 
    Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

            /Users/thomas/.rvm/rubies/ruby-1.9.3-p392/bin/ruby extconf.rb --with-pg-config=/usr/pgsql-9.2/bin/pg_config
    Using config values from /usr/pgsql-9.2/bin/pg_config
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    sh: /usr/pgsql-9.2/bin/pg_config: No such file or directory
    checking for libpq-fe.h... yes
    checking for libpq/libpq-fs.h... yes
    checking for PQconnectdb() in -lpq... yes
    checking for PQconnectionUsedPassword()... yes
    checking for PQisthreadsafe()... yes
    checking for PQprepare()... yes
    checking for …
Run Code Online (Sandbox Code Playgroud)

gem bundler pg

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