Rails 3 - 路由错误,因为它之前在我的旧笔记本电脑上工作但现在出错了而感到困惑

时间:2014-05-26 04:47:46

标签: ruby ruby-on-rails-3 routes

我使用Ruby 1.9.3在rails 3.0.7上运行应用程序,而在我的旧开发笔记本电脑上运行我的路由文件中的所有内容都没问题。切换到新计算机后,我不得不使用旧版宝石的精确版本捆绑安装我的gemlist。但是当我尝试启动我的开发服务器时,我的路由文件出错了。不知道为什么,谁能告诉我哪里出错了>

非常感谢。

错误

/Users/iHal9000/.rvm/gems/ruby-1.9.3-p547@rails3gp/gems/activesupport-3.0.7/lib/active_support/dependencies.rb:235:in `load': /Users/iHal9000/Desktop/gp_public_gp/config/routes.rb:67: syntax error, unexpected keyword_do_block (SyntaxError)
     resources :stores, :only => :index, do  #
                                           ^
/Users/iHal9000/Desktop/gp_public_gp/config/routes.rb:73: syntax error, unexpected keyword_do_block
/Users/iHal9000/Desktop/gp_public_gp/config/routes.rb:76: syntax error, unexpected keyword_end, expecting $end

的routes.rb

resources :users do
     member do
     get :following, :followers 
     end
     resources :posts, :only => :index
     resources :stores, :only => :index, do  #line 67
     resources :posts, :only => :index
     end
     resources :collections do
       resources :posts, :only => :index
     end
     resources :artists, :only => :index, do #line 73
     do resources :posts, :only => :index
     end
  end #line 76

1 个答案:

答案 0 :(得分:0)

正如 @jjing 所提到的那样,你必须删除 67 73 行中的trailing commas,并且还必须编辑第 74 行也可以删除do。请尝试将routes.rb文件更新为

resources :users do
     member do
     get :following, :followers 
     end

     resources :posts, :only => :index
     resources :stores, :only => :index do  #here remove ,
     resources :posts, :only => :index
     end

     resources :collections do
     resources :posts, :only => :index #here also remove ,
     end

     resources :artists, :only => :index do 
     resources :posts, :only => :index #here remove do
     end
  end

这应该有效!