你能告诉我路由我在哪里出错吗?以及我可以做什么来纠正



我终端尝试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 =>"欢迎#索引"

相关内容

最新更新