Notes posted by schmidt
RSS feed
@ssoroka and @drova and future readers
I guess these two have already found a solution, but future readers might have not. index and references do not map perfectly
change_table :foo do |t| t.references :bar t.index :bar_id end
references gets the model name while index gets the column name.

Not working in create_table
When using the index method within a create_table statement, it does not have any side effect - at least not in MySQL.
create_table :comment do |t| t.belongs_to :post t.timestamps # not working inside create_table ! t.index :post_id end
It is working properly in change_table though
change_table :comment do |t| t.belongs_to :user # this works inside change_table t.index :user_id end
Unfortunately this flaw is not reported in any way. The index is just not created.
I have only tested this with the mysql2 driver in Rails 2.3.x. I’m not sure, if this happens in other versions/adapters as well.

Set ids when using a collection of values (cont.)
Concerning greeneggs614’s post:
The following version would be a bit more intention revealing while providing the same output:
<% Car.each do |c| %> <%= check_box_tag "car_ids[]", c.id, :id => "car_ids_#{c.id}" %> <% end %>

Setting a custom Content type
The given example seems to be broken. The :mime_type option as well as the [] access on the Mime::Type class are both not working.
The following code allows the custom setting of content types as intended by the original example:
class PostsController < ActionController::Base def show @post = Post.find(params[:id]) respond_to do |format| format.html format.ics { render :text => post.to_ics, :content_type => Mime::Type.lookup("text/calendar") } format.xml { render :xml => @people.to_xml } end end end

Using global $! to address exception
@noxyu3m: Your code is actually syntactically wrong. The global is called $!
Your code should have been:
def create @model = Model.new(params[:model) @model.save! rescue logger.error($!.to_s) end
Although I would prefer
def create @model = Model.new(params[:model) @model.save! rescue ActiveRecord::RecordInvalid logger.error($!.to_s) end
to only catch expected exceptions, just like the documentation proposed.