How to get a Rails project to start with index.html.erb instead of index.html?

My page index.htmlfor my project needs some Ruby code, so I need to change it to an extension .erb. How to configure Rails to identify a file index.html.erbas a project start page instead of a file index.html?

+3
source share
4 answers

You need to configure the path map.rootin the file config/routes.rb.

map.root :controller => "blogs"

# This would recognize http://www.example.com/ as
params = { :controller => 'blogs', :action => 'index' }

# and provide these named routes
root_url   # => 'http://www.example.com/'
root_path  # => ''

http://api.rubyonrails.org/classes/ActionController/Routing.html

+6
source

public / index.html is a flat file and does not go through any templates (everything in / public / looks like this.)

, . URL map.root:

map.root :controller => 'home'
+2

Or you can make root for:

config / routes.rb

    root to: 'index.html.erb'

Be sure to delete the index.html file

+1
source

The answers here are out of date. Assuming the file index.html.erbis under the controller and is called "patients". In rails 3 you would do it like this:

match "/" => "patients#index"
0
source

Source: https://habr.com/ru/post/1711832/


All Articles