
This is the readme for version 1.x of Mobility. If you are using an earlier version (0.8.x or earlier), you probably want the readme on the 0-8 branch. Mobility is a gem for storing and retrieving translations as attributes on a class. These translations could be the content of blog posts, captions on images, tags on bookmarks, or anything else you might want to store in different languages. For e
5.1.0のbetaがでて、そろそろ4.2もサポート範囲外になりそうなので、4.2から5.0にアップデートすることにしましたので、 色々作業した内容をメモって行きます。 本当は5.1まで一気にあげたい所ですが、まだbetaということで、一旦5.0.2に。 なあに、メジャーバージョンアップに比べればマイナーバージョンアップだし、きっと影響無いに決まってる。(慢心) Rails 5へのアップグレード手順メモ(Rails 4.2.6 => 5.0.0)を参考に作業 http://qiita.com/ryo511/items/2a387df126268fec8c78 を参照 gem のアップデート Rails update ApplicationRecordをActiveRecordのモデルのベースクラスにする を実施。 rubyは既に2.4に切り替え済み、 ApplicationJobは使ってな
Implementing inheritance with params: CreateProducts < ActiveRecord::Migration[5.0] Follow @makagon In Rails 5 each migration class is inherited from ActiveRecord::Migration[5.0]. It looks quite unusual to see that [5.0] part at the end of the parent class. In this article I'll describe why we might need it and how it works. It all started from the message in dry-rb channel on Gitter. Somebody ask
Ruby on Rails 8.0.2 Module ActiveRecord::Integration::ClassMethods activerecord/lib/active_record/integration.rb Defines your model’s to_param method to generate “pretty” URLs using method_name, which can be any attribute or method that responds to to_s. class User < ActiveRecord::Base to_param :name end user = User.find_by(name: 'Fancy Pants') user.id # => 123 user_path(user) # => "/users/123-fan
追記:activerecord-count_loaderはactiverecord-precountに変わりました。使い方はこちら。 ActiveRecordでassociationを読むためにN+1クエリが出てしまった場合、 includesなどのメソッドを利用することで発行されるクエリの数を減らすことができる。*1 ところが、それがcountクエリになると、eager loading用のメソッドでクエリの数を減らすことができない。 そこで、N+1 countクエリを潰す方法を調べ、まとめてみた。 ActiveRecordでN+1 countクエリを潰す3つの方法 TweetとFavoriteというモデルがあったとして、Tweetの全カラムと、各TweetのFavoriteの数だけ欲しい場合にN+1 countクエリを潰す方法を示す。 1. counter_cacheを使う class
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 have an issue with the uniq method. I have a database with a table as below. MariaDB [hpbx_development]> select * from asterisk_commands; +-------+-----------------+---------------------+---------------------+-----------+----------+-------------------+ | id | command | created_at | updated_at | completed | override | virtual_server_id | +-------+-----------------+---------------------+----------
Rails 5から、production environmentでのDB破壊系のtaskの実行を防止する仕組みが入りました。 例えば、production environmentでdb:dropを実行しようとすると、下記のようなエラー(ActiveRecord::ProtectedEnvironmentError)が発生します。 $ RAILS_ENV=production ./bin/rails db:drop rails aborted! ActiveRecord::ProtectedEnvironmentError: You are attempting to run a destructive action against your 'production' database If you are sure you want to continue, run the same co
Today we are open-sourcing our ODBC adapter for ActiveRecord, which allows Ruby on Rails applications to communicate with ODBC-compliant databases. The impetus for this work was an effort to update one of our APIs to run with the latest Rails and ruby. Along the way we released Rails 3.2.x, 4.2.x, and 5.0.x versions of the adapter, along with deploying incremental upgrades to our API as we went. B
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" =>
以前に書いたコードを読んでいると、1カラムの値だけを変えるからといって、update_attribute メソッドを使っている部分があった。これはあまりよくない update_attribute とupdate_attribtues の違い 前者は1つのカラムの値を、後者は複数のカラムの値を更新できる。という違い以上に、「update_attribute メソッドはvalidation なしに更新、update_attributes メソッドはvalidation ありで更新」という違いがあります。 つまり、update_attribute 使うと、検証処理なしに、値が更新されてしまう。ソースを見ると、update_attribute の方は、save(false) を使って更新しているのが分かる。 activerecord/lib/active_record/base.rb at mas
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く