My route returns a blank view (no html when I do view source)

瘦欲@ 提交于 2019-12-11 01:38:43

问题


I am brand new to Ruby on Rails and I have been trying to get a simple default route set up and working. When I try to run my application I get a blank result (if I do a view source, there is nothing there).

Here are the relevant files (not sure if I am missing something that would be useful).

app/config/routes.rb

Blog::Application.routes.draw do
  root :to => "home#index"
end

app/views/home/index.html.erb

<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>

app/controllers/home_controller.rb

class HomeController < ApplicationController
  def index
  end
end

app/views/layouts/application.html.erb

<!DOCTYPE html>
<html>
<head>
  <title>Benji</title>
  <%= stylesheet_link_tag :all %>
  <%= javascript_include_tag :defaults %>
  <%= csrf_meta_tag %>
</head>
<body>

<%= yield %>

</body>
</html>

When I try to run my application, I go to http://localhost:3000 and nothing shows up. If I do a view source, it is empty.

If do rake routes this is the result:

JESSE-GAVINs-MacBook-Pro-17:benji jesse$ rake routes
(in /Users/jesse/Dev/benji)
root  /(.:format) {:action=>"index", :controller=>"home"}
JESSE-GAVINs-MacBook-Pro-17:benji jesse$

In my development.log file I see this:

Started GET "/" for 127.0.0.1 at Tue Sep 07 10:44:10 -0500 2010
  Processing by HomeController#index as HTML
Rendered home/index.html.erb within layouts/application (2.8ms)
Completed 200 OK in 15ms (Views: 14.7ms | ActiveRecord: 0.0ms)

What could be the issue? How do I go about solving this?


回答1:


Solved (sort of...)

It works just fine when I started the rails server on a different port.

It was my understanding that I didn't need to restart the server in order for it to detect changes in the code.

Sorry about the waste of time, I just didn't know which tree I needed to bark up. I learned some things along the way.




回答2:


As you're playing with Routes, you absolutely need to restart the server. I don't know if this is part of the problem, but most (all?) things under config/ need the server to be restarted to take effect, particularly routes and environment



来源:https://stackoverflow.com/questions/3659445/my-route-returns-a-blank-view-no-html-when-i-do-view-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!