3

Rails.root: /home/chris/rails_projects/app1

I get the message about routes. my routes.rb files show:

I do not know how to approach this at all. I am using Ubuntu 12.04 in Virtualbox.

Rails.application.routes.draw do

  # The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  # root 'welcome#index'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

  # Example resource route (maps HTTP verbs to controller actions automatically):
  #   resources :products

  # Example resource route with options:
  #   resources :products do
  #     member do
  #       get 'short'
  #       post 'toggle'
  #     end
  #
  #     collection do
  #       get 'sold'
  #     end
  #   end

  # Example resource route with sub-resources:
  #   resources :products do
  #     resources :comments, :sales
  #     resource :seller
  #   end

  # Example resource route with more complex sub-resources:
  #   resources :products do
  #     resources :comments
  #     resources :sales do
  #       get 'recent', on: :collection
  #     end
  #   end

  # Example resource route with concerns:
  #   concern :toggleable do
  #     post 'toggle'
  #   end
  #   resources :posts, concerns: :toggleable
  #   resources :photos, concerns: :toggleable

  # Example resource route within a namespace:
  #   namespace :admin do
  #     # Directs /admin/products/* to Admin::ProductsController
  #     # (app/controllers/admin/products_controller.rb)
  #     resources :products
  #   end
end

2 Answers2

1

You need to create a controller and a view to direct your app somewhere.

Then you need to route your app to that action by editing your routes file. For example you can uncomment the line:

 root 'welcome#index'

This will then mean that when you navigate to the root of your site at the root directory (/app1) will go to the welcome controller, to its index action.

To learn more, have a look at: http://guides.rubyonrails.org/routing.html#using-root

olive_tree
  • 1,417
  • 16
  • 23
  • Error is `No route matches [GET] “/app1”` so it's not about root route also in a new application if you don't have any root route then rails 4 has default root route, checkout http://guides.rubyonrails.org/getting_started.html#hello-rails-bang :) – Mandeep Aug 10 '14 at 05:47
0

Routes

You need to define the routes your application will use, as follows:

#config/routes.rb
root 'application#index'

This will direct any of the "homepage" traffic to the following controller/action:

#app/controllers/application_controller.rb
Class ApplicationController < ActionController::Base
   def index
   end
end

--

Routing in Rails

You have to remember that Rails is an MVC-centric web application framework

This means every time you wish to access a "url", you need to define the "route" in your routes.rb file. The way to do this is to reference the relevant controller#actions in your routes file - using the resources method:

#config/routes.rb
root "application#index"
resources :controller_1, :controller_2

As Rails is object-orientated, the routes of your application will generally have to reflect the various resources it has inside. Most people try and define routes based on the presumed "flow" of the app - the truth is that you want to construct them around objects, which typically means controller and/or models

Richard Peck
  • 76,116
  • 9
  • 93
  • 147