How to do static content in Rails?

后端 未结 8 947
孤城傲影
孤城傲影 2020-11-30 17:47

Looking at different options:

One is to just put the static pages in the public/ folder, but I do want the header from layout/application to be consistent.

I

8条回答
  •  盖世英雄少女心
    2020-11-30 18:27

    Considering if u have 1 Home Controller with couple method like show, aboutus, privacy :

    class HomesController < ApplicationController
      def show
      end
      def privacy
      end
      def aboutus
      end
    end
    

    And map the show method to your root, and map the other to some named routes like

    map.root      :controller => "homes", :action => "show"
    map.aboutus "/aboutus", :controller => "homes", :action => "aboutus"
    map.privacy "/privacy", :controller => "homes", :action => "privacy"
    

    And with view for each

    app/views/homes/aboutus.html.erb --> you get http://localhost:3000/aboutus
    app/views/homes/show.html.erb --> you get http://localhost:3000 (root)
    app/views/homes/privacy.html.erb --> you get http://localhost:3000/privacy
    

    All using the same layout at app/views/layout/application.html.erb

提交回复
热议问题