lib/generators/layout/navigation/navigation_generator.rb in rails_layout-1.0.14 vs lib/generators/layout/navigation/navigation_generator.rb in rails_layout-1.0.15

- old
+ new

@@ -28,15 +28,32 @@ <% end %> LINKS end end # USERS - if Dir.glob("app/views/users/index.html.{#{ext},erb}").any? - append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS + if Object.const_defined?('User') + if User.column_names.include? 'role' + # suitable for role-based authorization + if Dir.glob("app/views/users/index.html.{#{ext},erb}").any? + append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS <% if user_signed_in? %> + <% if current_user.admin? %> + <li><%= link_to 'Users', users_path %></li> + <% end %> +<% end %> +LINKS + end + end + else + # suitable for simple authentication + if Dir.glob("app/views/users/index.html.{#{ext},erb}").any? + append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS +<% if user_signed_in? %> <li><%= link_to 'Users', users_path %></li> <% end %> LINKS + end + end end end # OMNIAUTH if File.exists?('config/initializers/omniauth.rb') append_file 'app/views/layouts/_navigation_links.html.erb' do <<-LINKS