2010-06-29 67 views
0

我有下面的代碼在我的控制器Rails的多張貼問題

<% 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 

:多=>真的,我得到以下錯誤但是,如果我不使用多部分,那麼它一切正常?

/!\ 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。

感謝

安迪

+0

這似乎是在我的Rails應用程序的奇怪的問題,如果我再創建一個新的這個消失。很奇怪。感謝所有人的幫助。 – 2010-06-30 08:09:26

回答

0

如果你包裝一下你form_for物體周圍的(在你的情況,@picture),您無需顯式地指定模式(:picture)或:url

也許下面將做的伎倆

<% form_for @picture, :html => { :multipart => true } do |f| %> 
    ... 
<% end %> 
+0

不錯的嘗試,但刪除符號和網址沒有區別。很好的提示知道雖然 – 2010-06-29 09:01:14

0

嘗試:

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

API適用於這樣的問題很好的例子;)

+0

不錯的嘗試,但刪除符號和網址沒有區別。好的提示知道雖然 – 2010-06-29 09:01:37

+0

你想創建一個新的圖片嗎?嘗試 <%form_for(Picture.new),:html => {:multipart => true} do | f | %> ... <% end %> 再次,從文檔。不知道還有什麼可能是問題,代碼本身看起來不錯 – DrColossos 2010-06-29 10:12:38

+0

是的,我試圖創建一個新的圖片。你的建議沒有修復它,我有一個可怕的感覺,我碰到了軌道上的錯誤。 Ouch – 2010-06-29 10:16:12

1

參考例子給出here

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

編輯

試舉pictures_url如下

​​
+0

不錯的嘗試,但改變順序沒有區別。 – 2010-06-29 09:00:47

+0

@Andrew: - 檢查我編輯的答案。 – Salil 2010-06-29 09:54:41

+0

也參考http://stackoverflow.com/questions/1508815/error-wrong-number-of-arguments-0-for-1 – Salil 2010-06-29 09:59:19