(注)動作確認はRails2.0.1 設定データやテストデータをテーブルへ流し込むために、今まではDB側の機能を使っていたのですが(load data infileとか)、少々面倒くさくなってきたのでAWDwR(2版)を調べて見たところ、p252あたりにデータロードに関する記述を見つけました。ただ、これはマイグレーションの利用が前提になっているみたいで、普段migrationを使っていない私には運用的に少々難しそうです。そこで本の内容を参考にrakeタスクを作ってみました。 lib/tasks/load_master_data.rakeを作成 lib/tasks/master_dataにcsvまたはymlのデータファイルを突っ込む rakeタスク実行 と言う手順です。 rakeタスクファイル作成 railsアプリのlib/tasksにload_master_data.rakeという名前のフ
アプリケーションをセットアップするのをRakeでやりたい やることは以下の3つ DB作成 DBスキーマ定義 初期データ作成 2,3番目はmigrationを使います create_user.rb class CreateUsers < ActiveRecord::Migration def self.up create_table :users do |t| t.column :family_name, :string, :limit => 40, :null => false t.column :first_name, :string, :limit => 40, :null => false t.column :login_name, :string, :limit => 40, :null => false t.column :hashed_password, :string, :l
DoRuby! (ドルビー!) は現場のエンジニアによる、主にRubyなどの技術に関する様々な実践ノウハウを集めた技術情報サイトです。 こんにちは。T氏です。今日は自作のRakeタスクを追加する方法をご紹介します。 Rakeタスクを追加するには、まず [RAILS_ROOT]/lib/tasks にsample.rakeファイルを作成します。 ファイルの中身の記述に関しては、 desc "説明文" task "実行タスク名" do ... end または => ["Rakeコマンド"] の2つをワンセットで書けばタスクが追加されます。 ではsample.rakeファイルにタスクを書いてみます。内容は下記になります。それぞれ、hello world!と表示するコマンド、db:drop,db:createを実行するコマンド、db:migrate,db:fixtures:loadを実行するタ
これでいいのか。 パラメーターを追加するとき。 url_for(params.merge(:foo => 'bar')) パラメーターを削除する時は、nilにする。 url_for(params.merge(:foo => nil)) ちなみに、viewでparamsを参照するのは反則な気がするのは私だけ?
accepts_nested_attributes_for / fields_for / attr_accessible wrangling I figured it was ripe time I figured out the new nested model forms in Rails 2.3. After a bit of wrestling with the various pieces I got it working and figured I should share with a Google a few key pieces which would have saved me a lot of time had I found them documented when I was searching. In this particular case I was ne
Class methods (1) included (<= v2.3.8) Instance methods (14) attribute_change (<= v2.3.8) attribute_changed? (<= v2.3.8) attribute_was (<= v2.3.8) attribute_will_change! (<= v2.3.8) changed (<= v2.3.8) changed? (<= v2.3.8) changed_attributes (<= v2.3.8) changes (<= v2.3.8) field_changed? (<= v2.3.8) reload_with_dirty (<= v2.3.8) save_with_dirty (<= v2.3.8) save_with_dirty! (<= v2.3.8) update_with_
This guide covers the association features of Active Record. After reading this guide, you will know how to: Understand the various types of associations. Declare associations between Active Record models. Choose the right association type for your models. Use Single Table Inheritance. Setting up and using Delegated Types. 1. Associations OverviewActive Record associations allow you to define rela
The most popular request on our new Feedback site was for the ability to easily manage multiple models in a single form. Thankfully Eloy Duran has a patch that does just this. But before we roll it into rails 2.3 we want to get some more feedback from you guys. Eloy's written this brief introduction to the patch, so take a look, and add any feedback you have to the lighthouse ticket. In Rails it h
Polymorphic URL helpers are methods for smart resolution to a named route call when given an Active Record model instance. They are to be used in combination with ActionController::Resources. These methods are useful when you want to generate correct URL or path to a RESTful resource without having to know the exact type of the record in question. Nested resources and/or namespaces are also suppor
I am using single table inheritance in my rails application, and want to explicitly set the type of an instance. I have the following; class Event < ActiveRecord::Base class SpecialEvent < Event which is implemented through single table inheritance. SpecialEvent.new works as expected, but I want to be able to do things like Event.new(:type => 'SpecialEvent') So I can create different sub_types eas
I'm using single table inheiritance (STI) to model the foods people eat and use in recipes in SF. STI is a way of representing a class and its subclasses in a single database table. The system defines a WeightPortion is a UserPortion is a Portion and there are a couple of other subclasses too. Rails handles this pretty well in the case that it has loaded all the subclasses into memory and worked o
fixtureは使うな 必ず破綻します machinistやfactory_girlを最初から導入するこ とを強くお勧め ただし、小さいアプリでは気にする必要はない 画像アップロードのテストがしづらい marsでは手動テスト用のテストデータとして fixtureを利用 3/27
Rails で違和感を覚えるのは、モデルにだけアプリケーション層に基底クラスが用意されていない所。違和感の正体はMVCの対称性だけではなく、実際に不便なのだ。ここで言う「アプリケーション層の基底クラス」とは、フレームワークレベルに直接定義するのは気がひけるけど、現在のアプリケーションで自分が定義するクラス全体には影響を与えたいような定義を行うクラスの意。例えば、セッション情報であれば、フレームワークレベルでなく、ApplicationControllerに定義するのが自然だし、現在の ActionPack でもそういう実装になっている。同じことがビュー(ヘルパ)においても可能だが、モデルだけはなぜか ActiveRecord::Base を直接継承しており、これが不便な局面が多々ある。 ApplicationModel 具体的には、既存のNKSKプロジェクトのモデル(クラス群)を別のプロジ
After trying to implement this in my project I am realizing just how scant and misleading the docs are on this topic. This thread is more of a request than a tutorial and I am hoping that some of you more experienced Rails folk will fill out the missing pieces of the puzzle.To make your jobs easier, I will cover what I do know...When to use STI: This structure is best used for models that have ide
I am trying to implement a restful app, but I have found some problems with the design, when I have thought in implementig STI. I will try to explain. Only as a example, you may suppose this models Class Person < ActiveRecord::Base has_many :widgets end Class Customer < Person end Class Employee < Person end Class Widget < ActiveRecord::Base belongs_to :person end Then I would like to define these
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く