lib/generators/devise/users/routes_helper.rb in cream-0.8.9.2 vs lib/generators/devise/users/routes_helper.rb in cream-0.8.9.3

- old
+ new

@@ -1,70 +1,75 @@ module DeviseUserGenerator module RoutesHelper def model_routes arg = "#{user_class.pluralize.underscore}" - arg << ", :admins" if admin_user? + # arg << ", :admins" if admin_user? arg end def routes_configure! - routes_content = routes_for_roles + routes_content = default_signin_routes << user_type_routes puts "Insert into routes: #{routes_content}" insert_into_routes do routes_content end end - - def routes_for_roles - say customize_note, :green - routes_customize_comment << roles_routes + def user_types_to_route + @user_types_to_route ||= user_types_except(:guest).delete_if do |user_type| + name_user_types = user_type.pluralize + is_there = !(read_routes_file =~ /devise_for :#{name_user_types}, :class_name =>/).nil? + debug! "not doing devise routing for #{name_user_types} as it is already there" if is_there + is_there + end end - def roles_except *names - roles.reject {|r| names.include? r.to_sym } + def default_signin_routes + name_default_users = user_class.underscore.gsub('/', '_').pluralize + default_user_class = user_class.classify + %Q{ + match '/sign_in' => 'main#index' + match '/log_in' => 'main#index' + + devise_scope do + get '/sign_in' => 'main#index', :as => :new_user_session + end + + devise_for :#{name_default_users}, :class_name => '#{default_user_class}', :controllers => {:sessions => 'main'} do + get '/sign_in' => 'main#index', :as => :new_user_session + end} end - def roles_routes - roles_to_route = roles_except(:guest).delete_if do |role| - is_there = !(read_routes_file =~ /devise_for :#{role.pluralize}, :class_name =>/).nil? - logger.debug "not doing devise routing for #{role.pluralize} as it is already there" if is_there - is_there - end - - roles_to_route.each do |role| - if read_routes_file =~ /devise_for :#{role.pluralize}/ - logger.debug "removing old devise routing for: #{role}" - File.remove_content_from routes_file, :where => /devise_for :#{role.pluralize}/ + def user_type_routes + user_types_to_route.each do |user_type| + name_user_types = user_type.pluralize + if read_routes_file =~ /devise_for :#{name_user_types}/ + debug! "removing old devise routing for: #{name_user_types}" + File.remove_content_from routes_file, :where => /devise_for :#{name_user_types}/ end end - logger.debug "performing devise role routing for: #{roles_to_route}" - roles_to_route.map do |role| - %Q{ - devise_for :#{role.pluralize}, :class_name => '#{role.classify}' - as :#{role} do - match "/#{role.pluralize}/sign_up" => "devise/registrations#new", :as => :#{role}_signup + debug! "performing devise role routing for: #{user_types_to_route}" + + user_types_to_route.map do |user_type| + name_user_types = user_type.pluralize + name_user_type = user_type.underscore.gsub('/', '_') + %Q{ + devise_for :#{name_user_types}, :class_name => '#{user_type.classify}', :controllers => {:registrations => 'devise/registrations', :sessions => 'main'} do + match "/#{name_user_types}/sign_in" => "devise/sessions#new", :as => :#{name_user_type}_signin + match "/#{name_user_types}/sign_up" => "devise/registrations#new", :as => :#{name_user_type}_signup end } end.join("\n") - end + end - - def routes_customize_comment - return "" if read_routes_file =~ /customize controller action/ - %q{ -# customize controller action if needed to render individual registration form for each role -# Example: -# match "/editors/sign_up" => "user_registrations#new_editor", :as => :editor_signup - -# 'user_registrations_controller.rb' with the action #new_editor -# def new_editor -# build_resource({}) -# end -# -# and the registration form in 'views/user_registrations/new_editor.html.erb' -# -} + protected + + def roles_except *names + roles.reject {|r| names.include? r.to_sym } end + + def user_types_except *names + user_types.reject {|r| user_types.include? r.to_sym } + end end end \ No newline at end of file