Ruby on rails RubyonRails第一个应用程序不工作
我将学习本教程: 我要提到的一件事是,我认为我使用的是与本教程不同的Rails版本。我使用的是2.3.14版 我正在Linux系统上工作。我建立了一个rails项目,因此:Ruby on rails RubyonRails第一个应用程序不工作,ruby-on-rails,ruby,Ruby On Rails,Ruby,我将学习本教程: 我要提到的一件事是,我认为我使用的是与本教程不同的Rails版本。我使用的是2.3.14版 我正在Linux系统上工作。我建立了一个rails项目,因此: rails myproject 正如教程所说,它设置了很多目录和文件(尽管教程使用的命令略有不同) 接下来,我通过创建控制器和视图来设置我的第一个应用程序,如下所示: ruby script/generate controller welcome index 这将在我的项目的app目录中的controllers和view
rails myproject
正如教程所说,它设置了很多目录和文件(尽管教程使用的命令略有不同)
接下来,我通过创建控制器和视图来设置我的第一个应用程序,如下所示:
ruby script/generate controller welcome index
这将在我的项目的app目录中的controllers和views子目录中创建文件。也就是说,我知道在views目录中有index.html.erb文件
接下来,我只想测试服务器:
ruby script/server
然后在我的浏览器中转到localhost:3000,它将我带到公共目录中的index.html文件
这就是问题所在。我希望被定向到视图子目录中的index.html.erb文件。因此,我转到config并打开routes.rb文件进行编辑。以下是我编辑的文件:
ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# Sample of named route:
# map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
# This route can be invoked with purchase_url(:id => product.id)
# Sample resource route (maps HTTP verbs to controller actions automatically):
# map.resources :products
# Sample resource route with options:
# map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }
# Sample resource route with sub-resources:
# map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
# Sample resource route with more complex sub-resources
# map.resources :products do |products|
# products.resources :comments
# products.resources :sales, :collection => { :recent => :get }
# end
# Sample resource route within a namespace:
# map.namespace :admin do |admin|
# # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
# admin.resources :products
# end
# You can have the root of your site routed with map.root -- just remember to delete public/index.html.
map.root :controller => "welcome#index"#I CHANGED THIS LINE
# See how all your routes lay out with "rake routes"
# Install the default routes as the lowest priority.
# Note: These default routes make all actions in every controller accessible via GET requests. You should
# consider removing or commenting them out if you're using named routes and resources.
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
我只在文件中做了一个更改。我所做的只是取消对这行的注释
map.root :controller => "welcome#index"
并将它指向我的index.html.erb文件(至少我认为我正在这样做)。
重新启动服务器仍会将我发送到index.html(在公共目录中)。所以我删除了这个文件。已关闭服务器,重新启动。现在我收到一条错误消息。我无法读取index.html.erb文件。我希望能得到任何帮助来解决这个问题。rails 2.x和rails 3.x有一些主要区别。如果您正在学习edgerails教程,那么这就是3.x。然后,您就可以轻松地完成本教程中的示例了
编辑:实际上,安装说明在教程中。如果您在安装ruby 1.9时遇到问题,我更喜欢管理ruby版本。可能是更流行的工具。rails 2.x和rails 3.x有一些主要区别。如果您正在学习edgerails教程,那么这就是3.x。然后,您就可以轻松地完成本教程中的示例了
编辑:实际上,安装说明在教程中。如果您在安装ruby 1.9时遇到问题,我更喜欢管理ruby版本。可能是更受欢迎的工具。试试这个版本的Rails指南:
但是,我强烈建议使用更新版本的Rails(目前为~3.2)开始学习。这可能会为您节省一些时间和精力。尝试此版本的Rails指南:
但是,我强烈建议使用更新版本的Rails(目前为~3.2)开始学习。这可能会为您节省一些时间和精力。您使用的是Rails v2.3.x,但使用的是edge guide(v3.2+)。你完全落后了。这两者之间有不相容之处。升级或使用。请逐字发布错误消息。正如@gg_所说,发布错误消息,这样我们可以帮助您使用Rails v2.3.x,但使用的是edge guide(v3.2+)。你完全落后了。这两者之间有不相容之处。请升级或使用。请逐字发布错误消息。正如@gg_所说,发布错误消息,这样我们可以帮助您纠正错误。升级rails之后,世界上一切都很好。你是对的。升级rails后,世界上一切都很好。