Rails多部分后期问题

时间:2010-06-29 08:14:48

标签: ruby-on-rails ruby

我的控制器中有以下代码

<% form_for @picture, :picture, :url=>pictures_url, :html => { :multipart => true } do | form | %>
  <%=form.file_field :image%>
  <%=submit_tag 'Save'%>
<%end%>

提交到以下控制器

class PicturesController < ApplicationController
  def create
    render :text=>1
  end
end

当我打开:multipart =&gt; true时,我收到以下错误,但如果我不使用multipart那么它全部正常执行?

/!\ FAILSAFE /!\  Tue Jun 29 09:59:47 +0100 2010
  Status: 500 Internal Server Error
  wrong number of arguments (1 for 0)
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/utils.rb:338:in `initi
ze'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/utils.rb:338:in `new'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/utils.rb:338:in `parse
ltipart'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/utils.rb:323:in `loop'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/utils.rb:323:in `parse
ltipart'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/request.rb:133:in `POS
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/methodoverride.rb:15:i
call'
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/par
_parser.rb:15:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/ses
n/cookie_store.rb:93:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/fai
fe.rb:26:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `synchro
e'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/lock.rb:11:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dis
cher.rb:114:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/rel
er.rb:34:in `run'
    C:/Ruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/dis
cher.rb:108:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/static.rb:31:in
all'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:46:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `each'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/urlmap.rb:40:in `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/rails/rack/log_tailer.rb:1
n `call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/content_length.rb:13:i
call'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:50:
`service'
    C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
    C:/Ruby/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:95:in `start'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `each'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:92:in `start'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:23:in `start'
    C:/Ruby/lib/ruby/1.8/webrick/server.rb:82:in `start'
    C:/Ruby/lib/ruby/gems/1.8/gems/rack-1.0.1/lib/rack/handler/webrick.rb:14:
`run'
    C:/Ruby/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/server.rb:111
    C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_orig
l_require'
    C:/Ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    script/server:3

任何建议,对不起,如果这是一个新手的错误,但我刚刚开始学习rails。

由于

安迪

3 个答案:

答案 0 :(得分:1)

给出here

的参考示例
<% form_for :picture,  @picture, :url=>pictures_url, :html => { :multipart => true } do | form | %>
  <%=form.file_field :image%>
  <%=submit_tag 'Save'%>
<%end%>

修改

尝试按以下方式提供pictures_url

<% form_for(@picture, :url => {:controller => "pictures", :action => "create"}, 
                      :html => {:multipart => true }) do |form| %>

答案 1 :(得分:0)

如果您将form_for包裹在对象周围(在您的情况下为@picture),则无需明确指定模型(:picture)或{{ 1}}。

也许以下方法可以解决问题

:url

答案 2 :(得分:0)

尝试:

<% form_for @picture, :html => { :multipart => true } do | form | %>
  <%=form.file_field :image%>
  <%=submit_tag 'Save'%>
<%end%>

API为这些问题提供了很好的例子;)