小编shi*_*ara的帖子

哪个CouchDB API用于Rails?

我目前正在调查CouchDB在我当前项目中的可能应用(用Rails编写),并希望从实际使用这些API的人那里获得一些反馈.你会推荐哪个?为什么?

  • ActiveCouch
  • CouchFoo
  • CouchRest
  • CouchRest摆幅
  • CouchPotato

couchdb ruby-on-rails nosql

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

15
推荐指数
2
解决办法
4442
查看次数

field_for和嵌套形式与mongoid

有人可以给我使用mongoid的嵌套表单的工作示例吗?

我的模特:

class Employee 
  include Mongoid::Document 
  field :first_name 
  field :last_name 
  embeds_one :address 
end

class Address 
  include Mongoid::Document 
  field :street 
  field :city 
  field :state 
  field :post_code 
  embedded_in :employee, :inverse_of => :address 
end
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails mongoid ruby-on-rails-3

15
推荐指数
1
解决办法
8361
查看次数

仅基于外键属性的关联类是什么?

简短:我有一个外键属性,想知道该外键字段的类(或引用表)是什么.

语境:

给出2个表:users(id, [other fields])issues(id, user_id, assigned_to, [other fields])

这是我的问题的活跃记录(提取不相关的部分)

class User < ActiveRecord::Base
  ...
end
class Issue < ActiveRecord::Base
  belongs_to :user
  belongs_to :assigned_user, :foreign_key => 'assigned_to', :class_name => 'User'
  ...
end
Run Code Online (Sandbox Code Playgroud)

我想做一个用户可读的更改日志记录.例如,当更改分配的用户时,我希望得到如下消息:Assigned to is changed from Otto to Zoltan.ActiveRecord具有changes一个很好的起点,但它只给我参考ID-s.要翻译成名称,我需要通过id读取用户.

对于关联:user来说,这很容易,因为我必须遵循惯例.但是如何获取assigned_to属性的相同信息(我想制作一般解决方案)?是否有可能弄清楚我们是否有给定属性的关联?我们可以提取该关联的类吗?

activerecord ruby-on-rails

13
推荐指数
2
解决办法
4220
查看次数

Rails 3和Rspec 2关闭各个测试的事务夹具

我正在将我的应用程序升级到Rails 3.我开始在Rails 3中使用Rspec 2.我需要为我的一些rspec测试关闭事务装置.之前我在我的模型规范中使用了以下代码

 before(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = false
  end

  after(:all) do
    ActiveSupport::TestCase.use_transactional_fixtures = true
    clean_engine_database
  end
Run Code Online (Sandbox Code Playgroud)

那现在给了我错误:

 Failure/Error: ActiveSupport::TestCase.use_transactional_fixtures = false
     undefined method `use_transactional_fixtures=' for ActiveSupport::TestCase:Class
Run Code Online (Sandbox Code Playgroud)

有没有办法在Rails 3中使用Rspec 2的每个测试块执行此操作?

rspec ruby-on-rails rspec2

11
推荐指数
1
解决办法
9110
查看次数

我如何通过ruby驱动程序了解MongoDB中我的文档大小

MongoDB中一个文档的限制是4Mo.我有一些文件真的很重,有很多数据.

我如何用ruby驱动程序知道我的文档在MongoDB中的大小?

ruby mongodb

10
推荐指数
2
解决办法
5909
查看次数

rails3 default_scope,以及迁移中的默认列值

class CreateCrews < ActiveRecord::Migration
  def self.up
    create_table :crews do |t|
      t.string :title
      t.text :description
      t.boolean :adult
      t.boolean :private
      t.integer :gender_id
      t.boolean :approved, :default => false
      t.timestamps
    end
  end
  def self.down
    drop_table :crews
  end
end


class Crew < ActiveRecord::Base
  has_many :users, :through => :crew_users
  belongs_to :user

  default_scope where(:approved => true)
end
Run Code Online (Sandbox Code Playgroud)

当我进入控制台并创建新记录时,"已批准"属性设置为true,为什么?

如何将其自动设置为默认值(false),如我的迁移文件中所示?

wojciech@vostro:~/work/ze$ rails console Loading development environment (Rails 3.0.0) ruby-1.9.2-p0 > c = Crew.new => #<Crew id: nil, title: nil, description: nil, adult: nil, private: nil, gender_id: nil, approved: …

migration ruby-on-rails default-scope ruby-on-rails-3

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

Ruby On Rails 3,form_tag远程响应Ajax请求

感谢阅读这篇文章.过去几天我一直坚持使用RoR的问题.我在index.html.erb下面有一个表单:

<head>
    <title>Ajax List Demo</title>
    <%= javascript_include_tag :defaults %>  
    <%= csrf_meta_tag %>  
</head>
<body>
  <h3>Add to list using Ajax</h3>

  <% form_tag :action => :list , :method=>:get, :remote=>true  do %>
    Enter the public url:<%= text_field_tag 'url' ,'', :size => 80 %>
    <%= submit_tag "Find" %>
  <% end %>

  <div id="my_list">
  </div>
</body>
Run Code Online (Sandbox Code Playgroud)

在控制器中我有:

 def list
    puts "here!!!!"
    reader = Reader.new
    @profiles =  reader.processURL(params[:url]) #profileList = 
    respond_to do |format|
      #format.html { render :partial=>true, :locals => { :profiles => @profiles}}#{          render :partial=>'profiles/list',:layout => …
Run Code Online (Sandbox Code Playgroud)

ajax ruby-on-rails ruby-on-rails-3

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

如何在Mongodb中更新/插入Object到内部列表?

Blog {
   id:"001"
   title:"This is a test blog",
   content:"...."
   comments:[{title:"comment1",content:".."},{title:"comment2",content:"..."}]    
}
Run Code Online (Sandbox Code Playgroud)

评论是博客中的内部列表.

但是我怎样才能只检索comment1?如何在博客中插入/更新新评论?如果我获得完整博客并将内容插入/更新到评论列表中,那么保存完整博客,如何解决并发问题?

谢谢.

concurrency save mongodb

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

如何语法检查(不呈现)Rails 3 ERB模板文件?

我正在尝试使用git pre-commit钩子对所有Ruby代码执行语法检查; GitHub上有一个位于https://github.com/cypher/git-ruby-syntax-check.

它尝试检查.erb文件,erb -x将它们转换为Ruby代码,然后将输出传递ruby -c给语法检查.不幸的是,Rails 3引入了一个与Ruby标准ERB 不兼容的自定义ERB解析器,因此预提交钩子在没有错误的地方找到错误.

是否有一些相当于erb -x将从Rails 3 ERB文件输出Ruby代码?

ruby-on-rails erb ruby-on-rails-3

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