2012-02-07 231 views
1

我刚开始学习RoR。这是我/app/trip_controller.rb文件路由错误没有路由匹配

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 

,这是我的routes.rb文件

Project::Application.routes.draw do 
end 

我/应用/视图文件夹中有下列文件

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

当我启动服务器并到达localhost:3000 /我的浏览器,我得到错误

No route matches [GET] "/trip" 

我需要在routes.rb文件中配置任何东西吗?

回答

1

我建议通过the routing guide的旅程,这可以帮助回答大部分(如果不是所有的)Rails新手和通过路径路由的人提出的问题。

要回答你的问题,是的,你需要配置routes.rb文件中的东西 - 这个文件是完成路由工作的核心。

2

您没有定义路线。你的routes.rb改成这样:

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

目的的路线是映射URL请求发送到您的控制器动作因为你没有任何路线定义你得到的路由错误。

检查此guide以获取有关路由的更多信息。

可能用来调试路由错误的最有用的命令是rake routes,它将输出所有定义的路由和路径名。

相关问题