0
線索的has_many章的Rails 3重定向到陌生的ID後創建
章belongs_to的線索
我的路線:
resources :trails do
member do
resources :chapters do
member do
resources :clues
end
end
end
end
從標準形式稱爲new.html視圖
從我的chapters_controller.rb
def creat
@trail = Trail.find(params[:id])
@chapter = @trail.chapters.build(params[:chapter])
if @chapter.save
flash.now[:status] = "Chapter created"
redirect_to @chapter
else
flash.now[:error] = "Name needed"
render 'new'
end
end
顯示路徑ID如何以1開始的日誌,然後在創建路徑ID後爲28(或chapter_id)。
Started POST "/trails/1/chapters" for 127.0.0.1 at Fri May 04 20:31:15 -0700 2012
Processing by ChaptersController#create as HTML
Parameters: {"commit"=>"Create New Chapter", "chapter"=>{"name"=>"", "gate"=>"", "assetkind"=>"url", "description"=>"", "asset"=>""}, "authenticity_token"=>"Puu7EL8yQEsU4/NimBdL6mJRXiXoFTbHb1DSYvFNDgI=", "utf8"=>"✓", "id"=>"1"}
.
.
.
(3.7ms) commit transaction
Redirected to http://localhost:3000/trails/28/chapters/28
我希望它重定向到..trails/1 /章節/ 28 ...當我更改URL,以反映我期望的路徑,正確的頁面顯示了正確的內容。
我遇到了一些問題,但我認爲這可能是幫助我弄清楚的一條線索。我的路線或我的社團有問題嗎?我有種重組我的關聯和嵌套他們,現在我有問題。
非常感謝您的時間和關注!
感謝您的反饋。到現在爲止還挺好!! – HappaGirl
如果這解決了您的問題,您應該通過點擊問題左側的複選框來接受答案。歡迎來到堆棧溢出! – coreyward