Trail has_many 章节
章节belongs_to trail
我的路线:
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/chapters/28 ...当我更改 url 以反映我期望的路径时,正确的页面会显示正确的内容。
我遇到了很多问题,但我认为这可能是帮助我解决问题的线索。我的路线或关联有问题吗?我有点重组了我的关联并将它们嵌套,现在我遇到了问题。
非常感谢您的时间和关注!