情況:對於證明,用戶可以創建單獨的URL別名,這些別名保存在表Testimonial中。Rails Alias路由 - 無效路由
所以,我創建了下面的路線在我的路線文件的末尾:
get '*alias', to: 'testimonial#show', as: 'testimonial_show'
這重定向到告別賽控制器節目,我取了正確的告別賽
問題: 通常,當我輸入網址www.example.com/jobs時,它會重定向到正確的作業頁面,但添加了上述(別名)行後,它會嘗試重定向到驗證控制器而不是作業。
這是我的路線:
mount Ckeditor::Engine => '/ckeditor'
# get "custom_page/testimonials"
match '/404', :to => 'home#not_found'
match '/422', :to => 'home#rejected'
match '/500', :to => 'home#server_error'
# resource :testimonial, :only => :index
get "testimonial", to: 'testimonial#index', as: 'testimonial_index'
get "testimonial/:id", to: 'testimonial#show', as: 'testimonial_show'
get "video_testimonial/:id", to: 'testimonial#show_video', as: 'video_testimonial_show'
get '/robots.txt' => 'home#robots'
get "custom_page/evp"
devise_for :users, :controllers => { :registrations => "registrations", :passwords => "passwords" }
devise_scope :user do
get "/users" => "registrations#new"
get "https://stackoverflow.com/users/password", to: "passwords#create"
end
as :user do
get "/login" => "home#index", :as => "new_user_session"
delete "/logout" => "devise/sessions#destroy"
end
# User created pages
resources :pages, :only => :show
resources :jobs, :only => [:show, :index, :create] do
resources :apply, :only => [:index, :create]
resources :share, :only => [:index, :create]
end
get "/quick_sign_in" => "quick_sign_in#index"
resources :apply, :only => :index do
collection { get 'add'}
end
namespace :user do
resource :profile, :only => [:show, :destroy, :update] do
get "remove", :on => :member
resources "attachments"
collection { get 'add_attachment'}
end
resources :applications, :only => [:index, :destroy] do
get "correspondence", :on => :collection
end
resources :jobs, :only => [:index, :create, :destroy]
end
root :to => 'home#index'
get '*alias', to: 'testimonial#show', as: 'testimonial_show'
編輯1:訪問作業頁面,當我訪問www.example.com/jobs與全球匹配加入我得到以下幾點:
No route matches {:controller=>"testimonial", :action=>"show", :id=>1, :locale=>:en}
編輯2:日誌沒有SQL部分:
[2014-06-10 09:37:08 +0200] Started GET "/jobs" for 127.0.0.1 at 2014-06-10 09:37:08 +0200
[2014-06-10 09:37:08 +0200] Rendered jobs/_search_sidebar.html.erb (4.3ms)
[2014-06-10 09:37:08 +0200] Rendered jobs/_jobs.html.erb (2.3ms)
[2014-06-10 09:37:08 +0200] Rendered jobs/_testimonial.html.erb (3.6ms)
[2014-06-10 09:37:08 +0200] Rendered jobs/index.html.erb within layouts/application (200.6ms)
[2014-06-10 09:37:08 +0200] Completed 500 Internal Server Error in 515.2ms
[2014-06-10 09:37:08 +0200]
ActionController::RoutingError (No route matches {:controller=>"testimonial", :action=>"show", :id=>1, :locale=>:en}):
app/views/jobs/_testimonial.html.erb:14:in `_app_views_jobs__testimonial_html_erb__481122295330206577_70303349814440'
app/views/jobs/index.html.erb:17:in `_app_views_jobs_index_html_erb__1584069629091687413_70303340318260'
編輯3:rake routes | grep的工作
也進行耙路線O/P | grep工作? ,你有一個命名空間用戶,www.example.com/user/jobs的o/p是什麼 – Bijendra
@GhostRider請注意編輯3. – Vinozio
爲/ jobs生成的url正確,嘗試在視圖中修正問題到一個錯誤的網址 – Bijendra