小编bul*_*ric的帖子

如何使用继承用户模型定义工厂

我遇到了以下问题:在我的应用程序中,我使用继承来定义我的用户模型:

class User
 include Mongoid::Document

 field :name...
 field :bla...
end


class CustomUser < User
 field :customuserfield...
end
Run Code Online (Sandbox Code Playgroud)

我如何编写工厂来映射我的规格中的这个类hirachie.并继续写作,不要重复自己.

FactoryGirl.define do 
  factory :user do
    name  "name"
    bla "bla"

    factory :custom_user do
      customfield "customfield"
    end
  end
end
Run Code Online (Sandbox Code Playgroud)

这对我不起作用,因为该课程也是"用户".使用"用户"我收到了无效错误,因为自定义字段在这里并不存在.是否有良好的做法,方法或方法来重新安排这样的事情.

ruby-on-rails ruby-on-rails-3 factory-bot

27
推荐指数
2
解决办法
9578
查看次数

ArgumentError:发送消息需要SMTP To地址.设置消息smtp_envelope_to,to,cc或bcc地址

我有一个带有以下邮件配置的rails 4应用程序:

config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host: 'myhost.com' }
  config.action_mailer.perform_deliveries = true

  config.action_mailer.smtp_settings = {
    :enable_starttls_auto => true,
    :address            => 'smtp.myhost.com',
    :port               => 587,
    :domain             => 'myhost.com',
    :authentication     => :login,
    :enable_starttls_auto => false,
    :tls                  => false,
    :openssl_verify_mode  => 'none',
    :ssl => false,
    :user_name          => "myusername",
    :password           => "mypassword"
  }
Run Code Online (Sandbox Code Playgroud)

每次我尝试发送带有测试邮件设置的邮件时:

class TestMailer < ActionMailer::Base

  default :from => "noreply@myhost.com"

  def welcome_email
    mail(:to => "testmail@mymailaddress.com", :subject => "Test mail", :body => "Test mail body")
  end
end

TestMailer.welcome_email.deliver
Run Code Online (Sandbox Code Playgroud)

我有这个例外:

ArgumentError:发送消息需要SMTP To地址.设置消息smtp_envelope_to,to,cc或bcc地址. …

ruby-on-rails actionmailer ruby-on-rails-4

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

用剪贴板和xterm编译vim

我想编译当前版本的vim:

+clipboard +xterm_clipboard and ruby support 
Run Code Online (Sandbox Code Playgroud)

但每次我编译它时clipboard,xterm_clipboard选项都没有启用.

是否需要lib或者我必须在配置步骤中添加任何其他选项吗?

./configure \
--enable-rubyinterp=dynamic \
--enable-cscope \
--enable-gui=auto \
--enable-gtk2-check \
--enable-gnome-check \
--with-features=huge \
--with-x 
 make && sudo make install
Run Code Online (Sandbox Code Playgroud)

vim clipboard

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

通过python使用蓝牙发送消息或数据

我如何通过python通过蓝牙发送消息而无需类型号码等密钥验证?

我使用了pybluez,但是我收到了这个错误:

File "./send", line 12, in <module>
    connect()
File "./send", line 8, in connect
    sock.connect((bd_addr, port))
File "<string>", line 5, in connect
    bluetooth.btcommon.BluetoothError: (111, 'Connection refused')
Run Code Online (Sandbox Code Playgroud)

这是代码

#!/usr/bin/python

import bluetooth

def connect ():
    bd_addr = "x:x:x:x:x:x"
    port = 1
    sock=bluetooth.BluetoothSocket(bluetooth.RFCOMM)
    sock.connect((bd_addr, port))
    sock.send("hello!!")
    sock.close()

connect()
Run Code Online (Sandbox Code Playgroud)

python bluetooth

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

有没有办法删除heroku上的分支

我正在使用heroku来托管我的应用程序.通过合并和rebase,我有两个不同阶段的应用程序.

本地主人与heroku上的主人不同.

推送到heroku大师失败了:

 ! [rejected]        master -> master (non-fast-forward) 
 error: failed to push some refs to 'git@heroku.com:xxxxx.git'             
 Merge the remote changes (e.g. 'git pull') before pushing again.  See the    
 'Note about fast-forwards' section of 'git push --help' for details.                                                                                 
Run Code Online (Sandbox Code Playgroud)

有没有办法删除heroku主人?然后我可以再次推送给Heroku大师..

git deployment heroku ruby-on-rails-3

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

什么"分配"

目前我正在尝试学习ruby on rails和测试框架rspek任何人都可以回答我在这个rspec测试中做什么

 describe "GET index" do
    it "assigns all mymodel as @mymodel" do
      mymodel = Factory(:mymodel)
      get :index
      assigns(:mymodels).should eq([mymodel])
    end
  end
Run Code Online (Sandbox Code Playgroud)

ruby testing rspec ruby-on-rails

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

凤凰相当于Rails.env.production?

我是凤凰和elixier的新手,但框架看起来非常有趣.目前我正在寻找相当于Rails环境助手.

Rails.env.production?
Rails.env.staging?

在凤凰城有类似的实现吗?

最好的祝福

埃里克

phoenix-framework

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

限制has_many与mongoid关联的对象数量

我想限制帖子和图片之间has_many关联中关联对象的数量:

在活跃的记录中我可以做类似的事情

class post < < ActiveRecord::Base
  has_many :pictures, :limit => 2
end
Run Code Online (Sandbox Code Playgroud)

但是mongoid通过限制引发异常:

无效选项:提供给关系的限制:图片.有效选项包括:as,autosave,dependent,foreign_key,order,class_name,extend,inverse_class_name,inverse_of,name,relation,validate.(Mongoid ::错误:: InvalidOptions)

有没有替代实现来重新定义:限制?

validation mongoid ruby-on-rails-3

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

宝石安装rqr错误?

我安装rqr时出错了有没有人知道这个comiling错误的原因?

---> lib
---> lib/rqr
<--- lib/rqr
<--- lib
---> ext
---> ext/rqr
/usr/local/rvm/rubies/ruby-1.9.2-p290/bin/ruby /home/bulleric/Desktop/rqr-0.2.2/ext/rqr/extconf.rb
checking for jpeglib.h... yes
checking for main() in -ljpeg... yes
checking for png.h... yes
checking for main() in -lpng... yes
checking for tiff.h... yes
checking for main() in -ltiff... yes
creating Makefile
<--- ext/rqr
<--- ext
---> lib
---> lib/rqr
<--- lib/rqr
<--- lib
---> ext
---> ext/rqr
make
g++ -I. -I/usr/local/rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/x86_64-linux -I/usr/local/rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1/ruby/backward -I/usr/local/rvm/rubies/ruby-1.9.2-p290/include/ruby-1.9.1 -I/home/bulleric/Desktop/rqr-0.2.2/ext/rqr -DHAVE_JPEGLIB_H -DHAVE_PNG_H -DHAVE_TIFF_H    -fPIC -O3 -ggdb -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith …
Run Code Online (Sandbox Code Playgroud)

ruby gem compilation

0
推荐指数
1
解决办法
583
查看次数

使用ruby编译vim

我试图在我的Mac Osx 10.7.3上编译vim我得到了这个错误

./configure --enable-rubyinterp 
make 

ld: library not found for -lruby.1.9.1
collect2: ld returned 1 exit status
make[1]: *** [vim] Error 1
make: *** [first] Error 2
Run Code Online (Sandbox Code Playgroud)

有谁知道我怎么可以安装这个库?

ruby vim compilation

0
推荐指数
1
解决办法
589
查看次数