我使用rvm来安装ruby 1.9.3.即使它已成功安装,它也抱怨libyaml.现在,每当我想安装一个宝石(比如铁轨)时,这个警告会显示出来:
It seems your ruby installation is missing psych (for YAML output). To eliminate this warning, please install libyaml and reinstall your ruby.
Run Code Online (Sandbox Code Playgroud)
我使用的是Mac OS X 10.7(Lion).
当我尝试运行bundle(bundle install)时,我总是得到
Installing pg (0.13.2) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/Users/ryan/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for pg_config... no
No pg_config... trying anyway. If building fails, please try again with
--with-pg-config=/path/to/pg_config
checking for libpq-fe.h... no
Can't find the 'libpq-fe.h header
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers. Check the mkmf.log file for more
details. You may need configuration options.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include …Run Code Online (Sandbox Code Playgroud) 如何在终端/控制台中运行此rake文件?
我在lib/tasks中的statistik.rake
desc "Importer statistikker"
namespace :reklamer do
task :iqmedier => :environment do
...
end
task :euroads => :environment do
...
end
task :mikkelsen => :environment do
...
end
task :orville => :environment do
...
end
end
Run Code Online (Sandbox Code Playgroud) 我需要current_user在Rspec/capybara请求规范中存根方法的响应.该方法在ApplicationControllerhelper_method中定义并使用helper_method.该方法应该只返回一个用户ID.在测试中,我希望这种方法每次都返回相同的用户ID.
或者,我可以通过设置session[:user_id]规范(这是什么current_user返回)来解决我的问题...但这似乎也不起作用.
这些都可能吗?
编辑:
这是我得到的(它不工作.它只运行正常的current_user方法).
require 'spec_helper'
describe "Login" do
before(:each) do
ApplicationController.stub(:current_user).and_return(User.first)
end
it "logs in" do
visit '/'
page.should have_content("Hey there user!")
end
end
Run Code Online (Sandbox Code Playgroud)
也不工作:
require 'spec_helper'
describe "Login" do
before(:each) do
@mock_controller = mock("ApplicationController")
@mock_controller.stub(:current_user).and_return(User.first)
end
it "logs in" do
visit '/'
page.should have_content("Hey there user!")
end
end
Run Code Online (Sandbox Code Playgroud) 只是想知道是否/如何在rspec存根链中传递参数.举个例子,假设我有以下行动:
def index
@payments = Payment.order(:updated_at).where(:paid => true)
@bad_payments = Payment.order(:some_other_field).where(:paid => false)
end
Run Code Online (Sandbox Code Playgroud)
在我的控制器规范中,我希望能够存根两种方法并返回不同的结果.如果只有@payments场地在行动中,我会使用类似的东西
Payment.stub_chain(:order, :where) { return_this }
Run Code Online (Sandbox Code Playgroud)
但是,当然,这将返回相同的值@bad_payments.
那么 - 简而言之,我如何包含:updated_at和:paid => true作为存根条件?
我怎样才能实现以下目标?我有两个模型(博客和读者)和一个JOIN表,它允许我在它们之间建立N:M关系:
class Blog < ActiveRecord::Base
has_many :blogs_readers, :dependent => :destroy
has_many :readers, :through => :blogs_readers
end
class Reader < ActiveRecord::Base
has_many :blogs_readers, :dependent => :destroy
has_many :blogs, :through => :blogs_readers
end
class BlogsReaders < ActiveRecord::Base
belongs_to :blog
belongs_to :reader
end
Run Code Online (Sandbox Code Playgroud)
我现在想做的是将读者添加到不同的博客中.但是,条件是我只能将博客添加到博客中.因此表中不得有任何重复(相同readerID,相同blogID)BlogsReaders.我怎样才能做到这一点?
第二个问题是,如何获得读者尚未订阅的博客列表(例如,填写下拉选择列表,然后可以将读者添加到另一个博客)?
我有一个名为'companies'的控制器,而不是每个公司的url用以下表示:id我想让url使用他们的:name,例如:url/company/microsoft而不是url/company/3.
在我的控制器中我假设我会
def show
@company = Company.find(params[:name])
end
Run Code Online (Sandbox Code Playgroud)
由于url中没有任何其他参数,我希望rails能理解:name引用了我公司模型中的:name列.我认为这里的魔法将在路线中,但我仍然坚持这一点.
我已经和Yii呆了几个月,之后我在我的项目中使用了主要的CodeIgniter,SilverStripe.有没有人知道一个好的基于Yii的CMS,例如基于Sapphire的SilverStripe或基于CodeIgniter的EE?
假设你是优秀的OOP编码器,我的经验是与Yii合作更容易和直接,但是Yii还很年轻,并且没有很多样本我可以快速组合起来进行真正的生产项目.
我发现的几个基于YII的CMS看起来并不是很有前途,或者可能处于非常早期的阶段,例如dotPlant,Web3CMS.
我通过rvm安装Ruby 1.9.3时出错.
rvm install 1.9.3-p0
Installing Ruby from source to: /home/alder/.rvm/rubies/ruby-1.9.3-p0, this may take a while depending on your cpu(s)...
ruby-1.9.3-p0 - #fetching
ruby-1.9.3-p0 - #downloading ruby-1.9.3-p0, this may take a while depending on your connection...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:00:02 --:--:-- 0^[[B^[[B^[[B^[[B^[[B^[[B^[100 9330k 100 9330k 0 0 112k 0 0:01:23 0:01:23 --:--:-- 64618
ruby-1.9.3-p0 - #extracting …Run Code Online (Sandbox Code Playgroud) 你如何检索一个IDsin 数组Mongoid?
arr=["id1","id2"]
User.where(:id=>arr)
Run Code Online (Sandbox Code Playgroud)
如果要检索其他属性,则可以轻松完成此操作
User.where(:nickname.in=>["kk","ll"])
Run Code Online (Sandbox Code Playgroud)
但我想知道如何在mongoid中做到这一点 - >这应该是一个非常简单和常见的操作