Welcome/home page in Ruby on Rails - best practice

后端 未结 7 1491
温柔的废话
温柔的废话 2020-12-07 09:05

My homepage (or welcome page) will consist of data from two models (lets call them authors and posts). I am new to rails and not sure what is the best way to accomplish this

相关标签:
7条回答
  • 2020-12-07 09:41

    This answer is as of Rails 3.2.1.

    First set up a Controller for pages, named for example static:

    $ rails generate controller static
    

    In file app/controllers/static_controller.rb:

    class StaticController < ApplicationController
        def index       
        end
    end
    

    Create the new View file app/views/index.html.erb

    And finally configure your config/routes.rb:

    MyApp::Application.routes.draw do
       match 'home', :to => "static#index"
       root :to => "static#index"
    end
    

    This will make both /home and / go to whatever you put in the View file you just created.

    0 讨论(0)
提交回复
热议问题