When I want to show default welcome page by routes.rb, I can add route like this:
root "rails/welcome#index"
Then, I want to render the same template in my controller out of curiosity. The template is in rails/railties/lib/rails/templates/rails/welcome/index.html.erb
I thought `render "controller/action" works for my own files, but it doesn't seem to work for built-in files.
def index
render "rails/welcome/index" # This shows error `Missing template rails/welcome/index`.
end
So, Is there a handy way to render built-in template?
Yes you can render the rails welcome page from your controller by using the Rails::WelcomeController
class WelcomeController < Rails::WelcomeController
end
Don't define the index
method in WelcomeController
. Rails will pick the index
method of Rails::WelcomeController
and will render the default welcome page.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.