Fixnums as Symbols Warning from collection_select
Rails 2.3.5, Ruby 1.86
I'm not really understanding this warning. I'm getting one warning for each record containted in @directories
when using @directories
in a collection_select
. I've tried playing around with the :id
instances using them differently but with no luck. I'm sure it's something simple (I'm still 开发者_开发技巧pretty new).
Thanks in Advance!
error:
C:/Ruby186/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/helpers/form_options_helper.rb:328:
warning: do not use Fixnums as Symbols
The offending code:
<% if !params[:directory].nil? %>
<%= collection_select :directory, :id, @directories, (:id).to_i, :name,
{:selected => params[:directory][:id].map{|id|id.to_i}}, {:size => 7, :multiple => true} %>
<% else %>
<%= collection_select :directory, :id, @directories, (:id).to_i, :name,
{:selected => @directory_ids}, {:size => 7, :multiple => true} %>
<% end %>
You're passing in (:id).to_i
as an argument to collection_select
. collection_select
then uses it as an argument to send
. Since (:id).to_i
is an integer and send
being called with an integer as an argument is almost always a mistake, send
emits the warning you get.
It should be noted that there is no reason to use :id.to_i
instead of just :id
here since the only difference between send(:symbol)
and send(:symbol.to_i)
is that the latter produces a warning.
精彩评论