开发者

Rails include page

How would I include a page from the public folder in one of my views? 开发者_如何学GoI want to include a single header like I do in PHP so when I make a change it affects all the other pages. (It is for multiple views)


For the most part, the only web pages in the public folder will be purely static (custom 404 pages, FAQ, etc). If you have a piece of static HTML that you'd like to be displayed in a lot of pages, a partial is what you're looking for.

A partial doesn't have to be tied to a controller. You can create the sub-directory:

/views/static

and fill it with a whole bunch of partials, so you would have:

/views/static/_my_first_partial.html.erb
/views/static/_my_second_partial.html.erb

and anywhere you want those fragments, you can do:

render :partial => "static/my_first_partial"

and voila, you're done!


I'm pretty new to rails, but I guess for such task you would use Layouts: Layouts and Rendering

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜