联系我们gem route conflict - Rails 4

时间:2013-11-16 16:17:32

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

我收到此错误:ActionController::UrlGenerationError in ContactUs::Contacts#new,使用此gem https://github.com/jdutil/contact_us

错误:No route matches {:controller=>"contact_us/pages", :action=>"home"}

发生错误的地方:

.col-xs-8
            %ul
                %li
                    = link_to "Home", :controller => 'pages', :action => 'home'
                %li
                    = link_to "About", :controller => 'pages', :action => 'about'
                %li

我的路线:

devise_for :users
resources :available_times

root :to => "pages#home"

get 'about' => 'pages#about'
get 'pricing' => 'pages#pricing'

get 'users/my-bookings' => 'available_times#index'
get 'users/x34' => 'available_times#create'
get 'users/test_func/:id/:time' => 'available_times#test_func'

宝石路线

Rails.application.routes.draw do
  resources :contacts,
    :controller => 'contact_us/contacts',
    :only       => [:new, :create]
  get '/contact-us' => 'contact_us/contacts#new', :as => :contact_us
end

1 个答案:

答案 0 :(得分:1)

看起来你有一个范围问题。视图在contact_us范围内呈现,并且调用该范围内的控制器将使其在contact_us/而不是整个应用中查找它。我不是直接使用:controller => 'pages', :action => 'home'生成路由的忠实粉丝,而是尝试使用路径助手。它可能会更好。

= link_to "Home", root_path
= link_to "About", about_path

在路线中:

get 'about' => 'pages#about', as: :about