我终端尝试rails server
时显示的问题!
/home/<user_name>/.rvm/gems/ruby-2.0.0-p353/gems/activesupport-4.0.2/lib/active_support/dependencies.rb:223:in `load': /home/salmanalam/rails_projects/blog/config/routes.rb:5: syntax error, unexpected ':', expecting keyword_end (SyntaxError)
post GET /posts/:id(.:format) posts#show
这是我的config/routes.rb
Blog::Application.routes.draw do
resources :posts
get "welcome/index"
root 'welcome#index'
post GET '/posts/:id(.:format)' 'posts#show'
您在路线结束时有一些无关(非)代码。您的整个routes.rb
应该读取这样的内容,而是:
# config/routes.rb
Blog::Application.routes.draw do
resources :posts
get "welcome/index"
root "welcome#index"
end
首先,您缺少对块的end
声明。然后,读取post GET '/posts/:id(.:format)' 'posts#show'
的代码的一部分实际上不是路由,而是从命令行运行rake routes
的一部分。它说Post
资源有show
路线。
我不确定它是如何在您的代码中获得的,但是将其删除应该解决您的问题。
您可以尝试一下吗命名空间'帖子',:defaults => {:格式=>'eg.json'}做匹配'/post/event/:id',:to =>" post#show",:method =>:获取结束
root:to =>"欢迎#索引"