2016-05-17 48 views
1

我有一個視圖目錄blogs。在該目錄中,你可以找到所有的標準,傳統的HTML視圖模板:在視圖目錄中組織.html.erb和.js.erb文件

# html files within the app/views/blogs directory 
    _form.html.erb 
    edit.html.erb 
    index.html.erb 
    new.html.erb 
    show.html.erb 

不過:我也有動態的改變網頁內容(大多隻是表格上的內容)一些Ajax的看法。目前他們都都混在.html.erb文件,這感覺那種混亂和無組織:

# now showing the html AND js files within the app/views/blogs directory 
    _form.html.erb 
    add_foobar.js.erb 
    add_barbazz.js.erb 
    edit.html.erb 
    filter_by_team.js.erb 
    filter_by_city.js.erb 
    filter_by_state.js.erb 
    index.html.erb 
    new.html.erb 
    show.html.erb 

我認爲這將是有意義的從js.erb文件單獨的.html.erb文件,但我不知道該怎麼辦這是因爲它們都屬於blogs目錄。

如何在此目錄中組織.js.erb.html.erb文件?

回答

1

你可以說你的行動哪兒模板

respond_to do |format| 
    format.js { render "blogs/js/filter_by_team" } 
end 

,並把JS模板爲views/blogs/js