我想知道有沒有人可以幫助這個......對我來說非常令人沮喪。Rails5路由和條件語句
首先,我對這一切仍然很陌生。非常抱歉,如果我得到一些術語錯誤。我已經完成了一些教程,現在正在研究我的第一個應用程序,沒有任何指導演練......它的進展緩慢:)
我有兩組頁面,一組我應該顯示一個側欄和一個組需要它。下面是我的路線......
Rails.application.routes.draw do
#----Pages----
root 'pages#home'
get '/home', to: 'pages#home'
get '/contact', to: 'pages#contact'
#----Users----
get '/app', to: 'users#app'
get 'users/new', to: 'users#new'
get '/users', to: 'users#index'
get '/signup', to: 'users#new'
post '/signup', to: 'users#create'
#----Sessions----
get '/login', to: 'sessions#new'
post '/login', to: 'sessions#create'
delete '/logout', to: 'sessions#destroy'
#----Projects----
get'/projects/:id', to: 'projects#show'
get '/projects', to: 'projects#index'
get '/projects/new', to: 'projects#new'
post '/projects/new', to: 'projects#create'
#----Hazards----
get'/hazards/:id', to: 'hazards#show'
get '/hazards', to: 'hazards#index'
get '/hazards/new', to: 'hazards#new'
#----Resources----
resources :users
resources :projects
resources :hazards
end
我有我的頭下面的代碼的正常工作......
<% if current_page?(app_path) ||
current_page?(users_path) ||
current_page?(projects_path) ||
current_page?(hazards_path)
<%= render 'layouts/sidebar' %>
<% end %>
它提供了一個側邊欄上面並沒有列出別人的路徑。但是...我希望從「project_path」所以/項目/ 6等添加到列表頁面上方爲了實現這一目標,我添加以下行上面的代碼...
current_page?(project_path(:id)
導致英寸..
<% if current_page?(app_path) ||
current_page?(users_path) ||
current_page?(projects_path) ||
current_page?(hazards_path) ||
current_page?(project_path(:id)) %>
<%= render 'layouts/sidebar' %>
<% end %>
一旦添加應用程序加載罰款,但側邊欄不會添加到項目頁面。所以,我想另一種方法如下...
current_page?(project_path(@project))
這項修訂後的項目頁面現在可正確顯示側邊欄,但是......沒有側邊欄的所有其他網頁失敗,出現以下錯誤加載。 ..
No route matches {:action=>"show", :controller=>"projects", :id=>nil} missing required keys: [:id]
我在我無計可施......我也曾嘗試
current_page?(project_path(params.permit))
Current_page?(project_path(project))
current_page?(project_path(project(params[:id])))
是否有人可以把我從我的痛苦......那不是誇張...純苦難。
非常感謝。
...如果我告訴你它現在03:51在上午,我在早上工作....看到我完全承諾...任何接受者 –