How can I turn: Person.all.pluck(:id, :name) to [{id: 1, name: 'joe'}, {id: 2, name: 'martin'}] without having to .map every value (since when I add or remove from the .pluck I have to do he same with the .map)
RubyのcloneとdupとActiveRecordのcloneとdupは別物なのでしょうか? 同じものです。Method#owner でメソッドが定義されたクラスが得られますが、下記のいずれも true になります。 Piyo.new.method(:clone).owner == Object.method(:clone).owner` Piyo.new.method(:dup).owner == Object.method(:dup).owner` ただし、clone の場合は initialize_clone、dup の場合は initialize_dup メソッドが呼ばれます (参考: initialize_clone, initialize_dup and initialize_copy in Ruby: Jon Leighton)。 ActiveRecord の場合、Act
I'm on Ruby 1.9.2, Rails 3.0.x and I use MySQL DB. I have a Messages Model, where one can post new messages every day. I have an index action where I want to display these messages grouped by both month and year. This basically is used to filter messages. My query looks like this:- @active_msgs = Messages.where('expiry > ?', Time.now).order('created_at DESC') I used the group_by function in Rails,
So I have a model that I want to retrieve records and group them by dates of the created_at field. But created_at is a datetime field, and I am only interested in the date part. So I am looking for something like a 2D array, first layer would a hash with date string as the key, second layer would be arrays with records. How should I do it? { "9/28/2012" => [record, record, record], "9/29/2012" =>
Is there a way that you can get a collection of all of the Models in your Rails app? Basically, can I do the likes of: - Models.each do |model| puts model.class.name end
Is there a way to exclude the results of recordset #1 from recordset #2 in Rails 3 or 4, Activerecord? I have tried this before with ugly code trying to remove the id's by adding them to a hash and excluding them from the query. Must be a clean way to remove certain id's or results from a recordset?
I have an array of objects, let's call it an Indicator. I want to run Indicator class methods (those of the def self.subjects variety, scopes, etc) on this array. The only way I know to run class methods on a group of objects is to have them be an ActiveRecord::Relation. So I end up resorting to adding a to_indicators method to Array. def to_indicators # TODO: Make this less terrible. Indicator.wh
I need to query comments made in one day. The field is part of the standard timestamps, is created_at. The selected date is coming from a date_select. How can I use ActiveRecord to do that? I need something like: "SELECT * FROM comments WHERE created_at BETWEEN '2010-02-03 00:00:00' AND '2010-02-03 23:59:59'"
I'm trying to upgrade my redmine from 1.3.0 to 2.0.0, but I have problems with the database migration. When I run the command: rake db:migrate RAILS_ENV=production it shows an error like rake aborted! uninitialized constant RAILS_ENV My error log is: ActiveRecord::SubclassNotFound (The single-table inheritance mechanism failed to locate the subclass: 'GoogleAppsAuthSource'. This error is raised be
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く