jacksparrow007
jacksparrow007

Reputation: 1328

Routing error No route matches

I just started learning RoR. This is my /app/trip_controller.rb file

class TripController < ApplicationController
 layout 'main'
 def index
 end
  def map
    session[:location] = Location.new(params[:location])
        @map = GMap.new("map_div")
        @map.control_init(:large_map => true, :map_type => true)
        @map.icon_global_init( GIcon.new(:image => "http://www.google.com/
                                      mapfiles/ms/icons/blue-pushpin.png",
        :shadow => "http://www.google.com/mapfiles/shadow50.png",
        :icon_size => GSize.new(32,32),
        :shadow_size => GSize.new(37,32),
        :icon_anchor => GPoint.new(9,32),
        :info_window_anchor => GPoint.new(9,2),
        :info_shadow_anchor => GPoint.new(18,25)),
        "icon_source")
        icon_source = Variable.new("icon_source")
        source = GMarker.new([session[:location].lat,
                            session[:location].long],
        :title => 'Source',
        :info_window => "Start here!",
        :icon => icon_source)
        @map.overlay_init(source)
        @map.center_zoom_init([session[:location].lat,
                         session[:location].long], 12)
        @location = session[:location].location
 end

end

And this is my routes.rb file

Project::Application.routes.draw do
 end

My /app/views folder has the following files

_search.rhtml
index.rhtml  
/layouts
     application.html.erb   main.rhtml
/trip
     _info.rhtml    _tabs.rhtml map.rhtml

When i start the server and got to localhost:3000/trip on my browser, I get the error

No route matches [GET] "/trip"

Do I need to configure anything in the routes.rb file?

Upvotes: 2

Views: 14220

Answers (3)

stevec
stevec

Reputation: 52768

I had the same error when I had a hyphen in a symbol instead of an underscore, e.g. I had this

get "select-plan/:property-id" => "static_pages#select_plan"

but it should have been this (underscore in property_id):

get "select-plan/:property_id" => "static_pages#select_plan"

Upvotes: 0

shime
shime

Reputation: 9018

You don't have a route defined. Change your routes.rb to this:

 Project::Application.routes.draw do
   get "trip" => "trip#map"
 end

Purpose of routes is to map URL requests to your controller actions and since you don't have any routes defined you get routing errors.

Check this guide for more info on routing.

Probably the most useful command you can use to debug routing errors is rake routes which will output the paths and names for all the routes defined.

Upvotes: 2

jefflunt
jefflunt

Reputation: 33954

I would advise a trip through the routing guide, which can help answer most, if not all of the questions that come up with folks who are new to Rails and routing through paths.

To answer your question, yes, you do need to configure stuff in the routes.rb file - this file is central to making the routing work at all.

Upvotes: 1

Related Questions