【问题标题】:I am working on An Ruby on Rails app我正在开发一个 Ruby on Rails 应用程序
【发布时间】:2016-12-26 03:55:48
【问题描述】:

我正在开发一个 Rails 应用程序。我遇到的问题是当我在关于和联系页面之间循环时。我总是得到错误

没有路线匹配 [GET] "/pages/pages/about"

没有路线匹配 [GET] "/pages/pages/contact"

我正在尝试将我的导航栏部分标签 href 更改为 "/about" 的路线,但发生同样的错误。它要求我使用命令 rake routes 并显示

$ rake routes
    restaurants GET    /restaurants(.:format)          restaurants#index
                POST   /restaurants(.:format)          restaurants#create
 new_restaurant GET    /restaurants/new(.:format)      restaurants#new
edit_restaurant GET    /restaurants/:id/edit(.:format) restaurants#edit
     restaurant GET    /restaurants/:id(.:format)      restaurants#show
                PUT    /restaurants/:id(.:format)      restaurants#update
                DELETE /restaurants/:id(.:format)      restaurants#destroy
    pages_about GET    /pages/about(.:format)          pages#about
           root        /                               restaurants#index
  pages_contact GET    /pages/contact(.:format)        pages#contact"

谁能帮帮我!!

【问题讨论】:

  • 请添加您的alink_to标签?
  • 你在哪里得到错误

标签: ruby-on-rails


【解决方案1】:

您的简介和联系方式位于 URL /pages/about/pages/contact 下,但您访问的 URL 是 /pages/pages/about,它不存在。

您可以在 rake 路由中看到系统中可能的 url。

你需要在你的网络应用中拥有链接

<%= link_to 'About', pages_about_path %>

<%= link_to 'Contact', pages_contact_path %>

【讨论】:

  • 感谢您的回复! 标签在哪里?就像在我的 application.html 或导航栏部分>
【解决方案2】:

在您的路线中,您可以执行类似的操作

#config/routes.rb
ClientCruiser::Application.routes.draw do
  ....
  match "contact" => "pages#contact", :as => :contact, via: :all
  match "about" => "pages#about", :as => :about, via: :all
  ....
  root :to => 'pages#index'
end

这个的输出

contact     /contact(.:format) pages#contact
  about     /about(.:format)   pages#about
   root GET /                  pages#index

你打电话的方式是

<%= link_to about_path, "About", class: '' %>
<%= link_to contact_path, "Contact", class: '' %>

【讨论】:

    猜你喜欢
    • 2019-07-26
    • 1970-01-01
    • 2012-09-11
    • 2012-09-15
    • 2011-05-03
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    • 1970-01-01
    相关资源
    最近更新 更多