title: undefined method `to_key' for #<Class:0x17a6408> -rails-3
body: <p>I am experiencing problems with undefined method `to_key' for, on a form for polymorphic upload.</p>
  
  <p>This is the form partial:</p>
  
  <pre><code>&lt;%= form_for [@parent, Upload], :html =&gt; { :multipart =&gt; true } do |f|  %&gt;
  
    &lt;div class="field"&gt;
      &lt;%= f.label :document %&gt;&lt;br /&gt;
      &lt;%= f.file_field :document %&gt;
    &lt;/div&gt;
  
    &lt;div class="actions"&gt;
      &lt;%= f.submit "Upload"%&gt;
    &lt;/div&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>This is the controller:</p>
  
  <pre><code>class UploadsController &lt; ApplicationController
    before_filter :find_parent
  
    respond_to :html, :js
  
    def index
      @uploads = @parent.uploads.all unless @uploads.blank?
      respond_with([@parent, @uploads])
    end
  
    def new
      @upload = @parent.uploads.new unless @uploads.blank?
    end
  
    def show
      @upload = @parent.upload.find(params[:upload_id])
    end
  
    def create
      # Associate the correct MIME type for the file since Flash will change it
      if  params[:Filedata]
        @upload.document = params[:Filedata]
        @upload.content_type = MIME::Types.type_for(@upload.original_filename).to_s
        @upload = @parent.uploads.build(params[:upload])
        if @upload.save
          flash[:notice] = "suceessfully saved upload"
          redirect_to [@parent, :uploads]
        else
          render :action =&gt; 'new'
        end
      end
    end
  
    def edit
      @upload = Upload.where(params[:id])
    end
    private
  
  
    def find_parent
      classes ||= []
      params.each do |name ,value|
        if name =~ /(.*?)_id/
          @parent =  classes &lt;&lt; $1.pluralize.classify.constantize.find(value)
        end
      end
      return unless classes.blank?
    end
  end
  </code></pre>
  
  <p>If i change</p>
  
  <pre><code>&lt;%= form_for [@parent, Upload], :html =&gt; { :multipart =&gt; true } do |f| %&gt;
  </code></pre>
  
  <p>to</p>
  
  <pre><code>&lt;%= form_for [parent, Upload], :html =&gt; { :multipart =&gt; true } do |f| %&gt;
  </code></pre>
  
  <p>I get a new error: undefined local variable or method `parent' for #&lt;#:0x21a30e0></p>
  
  <p>This is the error trace:</p>
  
  <pre><code>ActionView::Template::Error (undefined method `to_key' for #&lt;Class:0x2205e88&gt;):
  1: &lt;%= render :partial =&gt; "uploads/uploadify" %&gt;
  2: 
  3: &lt;%= form_for [@parent, Upload], :html =&gt; { :multipart =&gt; true } do |f|  %&gt;
  4: 
  5: 
  6:  &lt;div class="field"&gt;
  </code></pre>
  
  <p>The "uploads/uploadify" partial is in this gist: <a href="https://gist.github.com/911635" rel="nofollow">https://gist.github.com/911635</a></p>
  
  <p>Any pointers will be helpful. Thanks</p>