基本的Hello,Rails!不工作

时间:2013-12-23 21:24:39

标签: ruby-on-rails

所以我对ruby和rails很新,我正在完全遵循这个教程:http://guides.rubyonrails.org/getting_started.html

我在使用基本的“Hello,Rails!”时遇到了问题。即使我按照并对

进行适当的更改,localhost:3000上的输出也是如此
app/views/welcome/index.html.erb

config/routes.rb

localhost:3000仍显示默认的Ruby on Rails欢迎屏幕而不是“Hello,Rails!”

文件中的

app/views/welcome/index.html.erb

我有以下代码:

<h1>Hello, Rails!</h1>
文件中的

config/routes.rb

我有以下代码:

Blog::Application.routes.draw do
  get "welcome/index"

  # You can have the root of your site routed with "root"
  # just remember to delete public/index.html.
   root :to => 'welcome#index'


end

我最初用

生成了控制器
rails generate controller welcome index

谢谢!

编辑:

我删除了public / index文件夹,现在在浏览器中出现以下错误:

ExecJS::RuntimeError in Welcome#index

Showing C:/blog/app/views/layouts/application.html.erb where line #6 raised:


  (in C:/blog/app/assets/javascripts/welcome.js.coffee)

Extracted source (around line #6):

3: <head>
4:   <title>Blog</title>
5:   <%= stylesheet_link_tag    "application", :media => "all" %>
6:   <%= javascript_include_tag "application" %>
7:   <%= csrf_meta_tags %>
8: </head>
9: <body>

Rails.root: C:/blog
Application Trace | Framework Trace | Full Trace

app/views/layouts/application.html.erb:6:in `_app_views_layouts_application_html_erb__607271608_36500496' 

编辑2:

rake路线给出:

welcome_index GET /welcome/index(.:format) welcome#index
        root           /                   welcome#

编辑3:

welcome.js.coffee的来源:

# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/

Gemfile的来源:

source 'https://rubygems.org'

gem 'rails', '3.2.13'

# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'

gem 'sqlite3'


# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sass-rails',   '~> 3.2.3'
  gem 'coffee-rails', '~> 3.2.1'

  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  gem 'therubyracer', :platforms => :ruby

  gem 'uglifier', '>= 1.0.3'
end

gem 'jquery-rails'

# To use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.0.0'

# To use Jbuilder templates for JSON
# gem 'jbuilder'

# Use unicorn as the app server
# gem 'unicorn'

# Deploy with Capistrano
# gem 'capistrano'

# To use debugger
# gem 'debugger'

4 个答案:

答案 0 :(得分:1)

检查您的控制器文件是否为welcome_controller.rb。另外检查类名是否为“WelcomeController”。

编辑:

您似乎遇到了ExecJS异常。请将一个javascript运行时添加到gemfile:

gem  'therubyracer'

我讨厌窗户。

答案 1 :(得分:1)

如果您不打算使用Turbolink,则可以在创建rails项目时运行new your_project_name --skip-turbolinks,以避免安装带有rails的Turbolink。这样,您将在学习基础知识时避免此类错误。

答案 2 :(得分:0)

解决了它:

转到

C:/blog/app/views/layouts/application.html.erb line #6

并删除javascript行。

但这真的很愚蠢,我认为真正的解决方案是切换到linux。

答案 3 :(得分:0)

是的,真的对我有用。从C:/blog/app/views/layouts/application.html.erb开始删除以下行:

<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>