2011-05-26 56 views
1

的Ruby 1.8.7,Rails的2.3.11Rails的對象將不能創建

主要問題:是什麼引發的Rails送我的索引頁爲對象類型試圖創建該類型的新對象後?沒有錯誤產生,沒有成功的消息,在數據庫中沒有新條目

我用ruby script/generate scaffold poster owner_id:integer event_id:integer來創建一個標準的腳手架,然後跑rake db:migrate。在不更改任何文件的情況下,我嘗試創建一個新的海報對象,並將它發送給/海報,而不是/ posters/show/1,因爲它應該這樣做。

這可能是幫助其他信息:

還有其他的對象類型已經在服務器上進行。當我試圖讓海報屬於belongs_to:owner和belong_to:event時,這個問題最初出現了。

如果信息到達要驗證的模型,它將返回一個錯誤空白要求的條目。如果我手動輸入數據到MySQL數據庫中,它會顯示在索引頁面中,並且可以在沒有問題的情況下進行編輯(並保存)。因此,我認爲這個問題要麼在控制器文件中,要麼在數據庫本身中,但是當我翻閱時沒有提到紅旗。

我對Rails有最少的(4個星期的課程)經驗,現在已經停留了三天。

的routes.rb:(註釋剝離線)

ActionController::Routing::Routes.draw do |map| 
    map.resources :posters 
    map.resources :place_informations 
    map.resources :building_polygon_coordinates 
    map.resources :alternate_names 
    map.resources :events 
    map.resources :hours_listings 
    map.resources :locations 

    map.connect 'json/buildings', :controller => 'json', :action => 'buildings' 
    map.resources :users 
    map.resources :buildings 

    map.root :controller => "home" 

    map.connect ':controller/:action/:id' 
    map.connect ':controller/:action/:id.:format' 
end 

development.log的適用部分:(尾端;只是爲了創造一個新的海報的嘗試; SQL調用剝離出來)

Processing PostersController#index (for <my IP address> at 2011-05-26 20:32:44) [GET] 
~~ SQL stuff, call timings ~~~ 
Rendering template within layouts/posters 
Rendering posters/index 
~~ SQL stuff, call timings ~~~ 


Processing PostersController#new (for <my IP address> at 2011-05-26 20:32:48) [GET] 
~~ SQL stuff, call timings ~~~ 
Rendering template within layouts/posters 
Rendering posters/new 
~~ SQL stuff, call timings ~~~ 



Processing PostersController#index (for <my IP address> at 2011-05-26 20:32:56) [GET] 
~~ SQL stuff, call timings ~~~ 
Rendering template within layouts/posters 
Rendering posters/index 
~~ SQL stuff, call timings ~~~ 

「拿到指標,獲得新的,得到指數」
應*「獲得指數,獲取新的,創建後,獲取顯示,獲取索引「

+0

將您的routes.rb粘貼在這裏 – 2011-05-26 23:15:47

+2

您的表單偶然發出GET請求嗎?您可以通過在按下提交按鈕時查看服務器的輸出來檢查這一點。 – 2011-05-26 23:21:11

+0

@Ryan:我......尷尬地不知道該怎麼做。服務器在Bluehost上運行,所以我沒有直接訪問控制檯,我不知道如何通過SSH查看輸出。 >< – Benjin 2011-05-27 00:10:22

回答

0

我弄明白了。

Apache中的DirectorySlash切換必須設置爲「Off」。我不確定爲什麼這樣做會影響它,但是將該行DirectorySlash Off添加到「.htaccess」後問題得到了解決。