2010-12-08 28 views
0

我有一個notes模型,它與users模型有多對多的關係。在notes控制器索引視圖我有這樣的形式:試圖提交表單時奇怪的導軌行爲

<form id='note_form' method="post" action="/notes/temp_path" > 
    <input type="hidden" name="authenticity_token" value="<%= form_authenticity_token %>" />   
    <input type="text" size="30" name="start_date" id="start_date"> 
</form> 

指向在notes控制器temp_path動作。出於某種原因,當提交此表單時,Rails不會運行temp_path操作中的代碼,而是嘗試加載某個音符,並且因爲它不能,所以它會重定向回索引。

Started POST "/notes/temp_path" for 127.0.0.1 at 2010-12-08 22:08:25 +1000 
DEPRECATION WARNING: Setting filter_parameter_logging in ActionController is deprecated and has no longer effect, please set 'config.filter_parameters' in config/application.rb instead. (called from <class:ApplicationController> at /Users/ben/rails_projects/note_prog/app/controllers/application_controller.rb:6) 
    Processing by NotesController#temp_path as HTML 
    Parameters: {"authenticity_token"=>"Ck6NmmYO86rvJSEsiqpIMkcaiErEhV7s/XMzjka15AI="} 
    User Load (0.3ms) SELECT "users".* FROM "users" WHERE ("users"."id" = 56) LIMIT 1 
    UserNote Load (0.2ms) SELECT "user_notes".* FROM "user_notes" WHERE ("user_notes"."note_id" = 0) 
Redirected to http://localhost:3000/notes 

我很肯定WHERE ("user_notes"."note_id" = 0)位是造成這個問題。但我不知道爲什麼這樣做甚至正在完成?基於上面的代碼,User Load (0.3ms) SELECT "users".* ...它看起來像是幕後Rails的東西。在temp_path動作中,無處需要加載現有的音符。我怎樣才能阻止呢?我正在使用Rails 3.0.1。謝謝閱讀。

回答

1

你應該告訴我們你的控制器的代碼。你有沒有'redirect_to'語句?有任何條件?

也許你在你的控制器中有一些過濾器,也許在ApplicationController中?從棄用警告中,我發現您可能有一些代碼。