In my previous blog post I described how you can run MRI Ruby on AWS Lambda. In this article I'll guide you through adding gems to the project: first faker, and then the mysql2 gem with activerecord, and finally we will have the Ruby code talk to an RDS instance, all this through an AWS Lambda. I recorded all my changes in this project, feel free to jump in where you want, you'll find commit point
RC 1もリリースされて流石にもう増える事はないと思うので、Rails 5で追加されたinitializerについてざっとまとめてみる。 # config/initializers/active_record_belongs_to_required_by_default.rb # Require `belongs_to` associations by default. This is a new Rails 5.0 # default, so it is introduced as a configuration option to ensure that apps # made on earlier versions of Rails are not affected when upgrading. Rails.application.config.active_record.belo
development: adapter: "sqlserver" mode: "odbc" host: "localhost" username: "mssql_user" password: "mssql_password" database: "database name" dataserver: "Server name" dsn: "mssql dsn" # 「コントロールパネル」 => 「ODBCデータソースアドミニストレータ」 で接続先のDBへのDSNを作成します。 # coding:utf-8 require "rubygems" require "activerecord-sqlserver-adapter" require "odbc" require "yaml" require "logger" @setting = YAML::load(File.open("da
RailsのMigrationの基本的なことから、カラム追加/削除、インデックス追加、NULL制約、カラム名変更などのレシピ集をまとめました。 動作確認 Rails 4.1 目次 1. Migrationの基礎 1.1. migrationファイルの作成 1.2. マイグレートの実施 rake db:migrateコマンド 1.3. マイグレートの適用状況確認 rake db:migrate:statusコマンド 1.4. データの投入 rake db:seedコマンド 1.5. マイグレーションで使えるデータ型一覧 2. Migrationのレシピ集 2.1. カラムの追加(add_column) 2.2. カラムの削除(remove_column) 2.3. データ型の変更(change_column) 2.4. インデックスやユニーク制約の追加/削除(add_index/remove
By default Rails/ActiveRecord 3 creates attribute accessors for all database table columns in each model. Columns with specific names cause errors because they result in ActiveRecord redefining a key method within either Ruby or ActiveRecord in an incompatible way. A classic example is any table with a column named ‘class’, though there are other possible examples. Put simply, this gem makes it ea
This reduces the size of a YAML encoded Active Record object by ~80% depending on the number of columns. There were a number of wasteful things that occurred when we encoded the objects before that have resulted in numerous wins - We were emitting the result of `attributes_before_type_cast` as a hack to work around some laziness issues - The name of an attribute was emitted multiple times, since t
Rails(ActiveRecord/Arel)で複雑なSELECT文を実行する方法をまとめました。 メリット、デメリットや使いどころなどまとめ途中なのであしからずお願いします。 動作確認 Ruby 2.2.0 Rails 4.2.0 Arel 6.0.0 目次 まとめ ER図 Active Record Arel 生SQL 1. まとめまず、個人的な意見として、それぞれの方法のメリット・デメリットをまとめました。 メリットデメリット ActiveRecord ・1, 2テーブル内での検索なら簡単に処理をかけれる ・返り値がActiveRecord::Relationやモデルのインスタンスなので扱いやすい ・複数のテーブルにまたがる検索で、検索条件、他テーブルのカラム値の扱いがしずらい ・CASE WHENやカラムなど行いづらい Arel 文字列でなくメソッドで検索文を記載できる(個人的に
RubyJunky.com A Ruby, Rails, and general programming blog by Brian VanLoo Rails ActiveRecord Serialize First off I have to admit I am not the best Googler in the world. So when I set out to figure out how to store a bunch of key/value pairs into a single text column in a database it is somewhat understandable that I turned up confusing results around Rails serialize. Unfortunately it looks like th
Rails 5 beta-1 wasrecently released and one of the notable change was introduction ofApplicationRecord. Up to Rails 4.2, all models inherited from ActiveRecord::Base. But startingfrom Rails 5, all models will inherit from ApplicationRecord. class Post < ApplicationRecordendWhat happened to ActiveRecord::Base ? Well not much changed in reality. Following file will be automatically added tomodels in
serialize-rails gemでJSONをDBに格納するという記事を書いたけど、わざわざgemを使わなくても第2引数に渡すオブジェクトがloadとdumpを実装していれば十分だった。ちなみにActiveRecord 3.2で確認。 たとえばURLをURIのオブジェクトとして扱いたい場合。 # app/models/uri_coder.rb class UriCoder # ActiveRecord::Baseのインスタンスが作られるときに呼ばれる。 # DBから読み出したときにはstringには保存されている値が渡され、 # newされたときにはnilが渡される。 def load(string) URI.parse(string) if string.present? end # DBに書き込むときに呼ばれる。 def dump(uri) uri.to_s end end # a
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く