Module: DeviseUserGenerator::RoutesHelper
- Included in:
- Devise::Generators::UsersGenerator
- Defined in:
- lib/generators/devise/users/routes_helper.rb
Instance Method Summary collapse
- #model_routes ⇒ Object
- #roles_except(*names) ⇒ Object
- #roles_routes ⇒ Object
- #routes_configure! ⇒ Object
- #routes_customize_comment ⇒ Object
- #routes_for_roles ⇒ Object
Instance Method Details
#model_routes ⇒ Object
3 4 5 6 7 |
# File 'lib/generators/devise/users/routes_helper.rb', line 3 def model_routes arg = "#{user_class.pluralize.underscore}" arg << ", :admins" if admin_user? arg end |
#roles_except(*names) ⇒ Object
23 24 25 |
# File 'lib/generators/devise/users/routes_helper.rb', line 23 def roles_except *names roles.reject {|r| names.include? r.to_sym } end |
#roles_routes ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/generators/devise/users/routes_helper.rb', line 27 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}/ 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 end } end.join("\n") end |
#routes_configure! ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/generators/devise/users/routes_helper.rb', line 9 def routes_configure! routes_content = routes_for_roles puts "Insert into routes: #{routes_content}" insert_into_routes do routes_content end end |
#routes_customize_comment ⇒ Object
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/generators/devise/users/routes_helper.rb', line 53 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' # } end |
#routes_for_roles ⇒ Object
17 18 19 20 21 |
# File 'lib/generators/devise/users/routes_helper.rb', line 17 def routes_for_roles say customize_note, :green routes_customize_comment << roles_routes end |