Make sure you include the following modules in ApplicationController
include ActionController::RackDelegation
include ActionController::Instrumentation
Completed in 5ms (View: 2, DB: 0) | 200 OK [http://0.0.0.0/items]
I came across with this weird IE bug(occurs in IE-6 and IE-7 not in IE-8) that throws a File Download Security Warning on form post.

File download security warning
This is the code for the corresponding action inside controller
def update
respond_to do |format|
format.js {....}
format.html {....}
end
end
* I guess this bug will only propagate if respond_to is used
I put a debugger after the respond_to line and made a http post request through IE6 and IE7 browsers and hooked into the request parameters.
request.format => #<Mime::Type:0x7b567a4 @string="image/jpeg", @synonyms=[], @symbol=nil > request.format.html? => nil
Making the same the request through Firefox returned this
request.format => #<Mime::Type:0x55da8b8 @string="text/html", @synonyms=["application/xhtml+xml"], @symbol=:html > request.format.html? => true request.format.js? => false
So one thing came into light that there is no Mime::Type registered for “images/jpeg” i.e format sent by IE
Looking at Rails 2.1.0 code actionpack/lib/action_controller/request.rb line no: 92
# Returns the Mime type for the format used in the request. If there is no format available, the first of the # accept types will be used. def format @format ||= parameters[:format] ? Mime::Type.lookup_by_extension(parameters[:format]) : accepts.first end
And that brought me to the solution.If no request format is available, which is the case with IE, then the first format will be picked up.So moving format.html above the format.js will solve the problem(or i should say format.html should be the first format defined)
def update
respond_to do |format|
format.html {....}
format.js {....}
end
end
Or we can also use format.any to our rescue(instead of moving format.html)
def update
respond_to do |format|
format.js {....}
format.any {....}
end
end
I ran into the following issue while i was dealing with a multi-model form where a Sport is being saved with associated Events
<%= render(:partial => "event", :collection => @sport.events) %>
This partial is being rendered for collection of events for new/edit Sport
<% new_or_existing = event.new_record? ? 'new' : 'existing' %>
<% prefix = "sport[#{new_or_existing}_event_attributes][]" %>
<% fields_for prefix, event do |e| -%>
<%= e.time_select("best_time") %>
<% end -%>
Here is the problem:
| For new Event, time_select name attribute should be: | sport[new][][best_time(5i)] |
| but this was being assigned: | sport[new][best_time(5i)] |
Following error is thrown when this form is submitted
Status: 500 Internal Server Error
Conflicting types for parameter containers. Expected an instance of Hash but found an instance of Array
For more information regarding this issue you can go through this ticket
After digging into rails code this came into light
# rails/actionpack/lib/action_view/helpers/form_helper.rb:508
if @object_name.sub!(/\[\]$/,"")
if object ||= @template_object.instance_variable_get("@#{Regexp.last_match.pre_match}") and object.respond_to?(:to_param)
@auto_index = object.to_param
else
raise ArgumentError, "object[] naming but object param and @object var don't exist or don't respond to to_param: #{object.inspect}"
end
end
So here @object_name would be “sport[new_event_attributes][]“
and @object_name.sub!(/\[\]$/,”") will return “sport[new_event_attributes]“
and @auto_index will set to nil
select_time internally calls option_with_prefix to assign name attribute for select element
#rails/actionpack/lib/action_view/helpers/date_helper.rb:664
def options_with_prefix(position, options)
prefix = "#{@object_name}"
if options[:index]
prefix << "[#{options[:index]}]"
elsif @auto_index
prefix < "#{prefix}[#{@method_name}(#{position}i)]")
end
end
Work around: pass a non nil index value along with date_select or time_select
<% new_or_existing = event.new_record? ? 'new' : 'existing' %>
<% prefix = "sport[#{new_or_existing}_event_attributes][]" %>
<% fields_for prefix, event do |e| -%>
<%= e.time_select("best_time", :index => event.id || "") %>
<% end -%>
time_zone_select produces option tags for almost any time zones in the world but if you want the list of US time zones only, without using the TZInfo library then you should add a file under the lib directory say us.rb and add the following code
class US
def self.all
TimeZone.us_zones
end
end
and in you views use
<%= time_zone_select object, method, nil, :model=>US %>