I have a case when clause where based on the URL that you're at, it will bring in different menu options. However, depending on some of the menus that you could be at, it doesn't recognize that you have some variables assigned. The system errors:
ActionController::RoutingError in Pages#users_page
Showing /home/initiald/RubymineProjects/SOWOnline/app/views/layouts/_navigation.html.erb where line #27 raised:
No route matches {:controller=>"results", :action=>"show"}
Here is the code that I have so far
<% case request.path %>
<% #ROOT AND SETTINGS %>
<% when '/', settings_path, '/guest' %>
<% #SURVEY 开发者_Python百科AND RESULTS %>
<% when '/sow_survey', '/surveys', '/results', result_path, results_path, available_surveys_path, take_survey_path, view_my_survey_path, edit_my_survey_path %>
<% if permitted_to? [:admin, :partner, :employee], :users %>
<%= link_to 'new survey', available_surveys_path %>
<%= link_to 'edit survey', results_path %>
<% end %>
<% #USERS %>
<% when '/register' , '/users', '/sow_users', edit_user_path %>
<% if permitted_to? [:admin, :partner, :employee], :users %>
<%= link_to 'new user', register_path %>
<%= link_to 'list users', list_users_path %>
<% end %>
<% else %>
<% end %>
There is no any result_path
without attributes, but there is result_path(result_id)
path, which is:
{:controller=>"results", :action=>"show", :id => your_paticular_id}
and looks like
/results/:id
UPD
Just use regular expression here:
<% when '/sow_survey', '/surveys', '/results', /\/results\/\d*/, results_path, available_surveys_path, take_survey_path, view_my_survey_path, edit_my_survey_path %>
And yes - your code is messy.
精彩评论