Reputation:
I am going through this tutorial: http://edgeguides.rubyonrails.org/getting_started.html One thing I will mention is that I think I am using a different version of Rails to the tutorial. I am using version 2.3.14 I am working on a Linux system. I set up a rails project thus:
rails myproject
WHich set up lots of directories and files as the tutorial said (although the tutorial uses slightly different commands)
Next, I set up my first app by creating a COntroller and View as follows:
ruby script/generate controller welcome index
This created files int he app directory of my project, in the controllers and views subdirectories. Namely, I know have the file index.html.erb in the views directory.
Next I just wanted to test the server:
ruby script/server
And then in my browser went to localhost:3000, which took me to the index.html file in the public directory.
This is where things go wrong. I want to be directed to the index.html.erb file in the views subdirectory. So, I went to config and opened the routes.rb file for editing. The following is my edited file:
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
I only made one change in the file. All I did was uncomment the line
map.root :controller => "welcome#index"
And point it to my index.html.erb file (at least that is what I think I am doing). Restarting the server still sends me to index.html (in public directory). So I deleted the file. Killed the server, restarted. Now I get an error message. I cannot read my index.html.erb file. I would like any help in fixing this.
Upvotes: 0
Views: 244
Reputation: 111
Try this version of the Rails guides: http://guides.rubyonrails.org/v2.3.11/
However, I would strongly recommend working with a more recent version of Rails (currently ~3.2) to start learning. It's likely to save you some time and effort.
Upvotes: 2
Reputation: 1240
There are some major differences in rails 2.x and rails 3.x. If you are following the edgerails tutorial, then that is 3.x. Install the new version of rails. You should then have no trouble following the examples in the tutorial.
Edit: In fact, the installation instructions are in the tutorial itself. If you are having trouble installing ruby 1.9, I rather like rbenv for managing ruby versions. RVM is perhaps the more popular tool for this.
Upvotes: 2