Skip to content

Use rails routes instead of rake routes, minimum rails is now 5.0 #843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

Vasfed
Copy link
Contributor

@Vasfed Vasfed commented Nov 24, 2020

This fixes #696
Major version bump is required because of minimum rails >= 5.0

@heaven
Copy link

heaven commented Jan 21, 2021

Doesn't work for me on Ruby 2.6.6 and Rails 6.1.

rake aborted!
Don't know how to build task 'routes' (See the list of available tasks with `rake --tasks`)
/Users/heaven/.rvm/gems/ruby-2.6.6@lively-letters/bin/ruby_executable_hooks:22:in `eval'
/Users/heaven/.rvm/gems/ruby-2.6.6@lively-letters/bin/ruby_executable_hooks:22:in `<main>'
(See full trace by running task with --trace)
config/routes.rb unchanged.

@saiqulhaq
Copy link

this one works with rails 6.1.0.rc

@stouset
Copy link

stouset commented Mar 7, 2021

Are there any plans to cut a release with this PR? annotate_routes doesn't work on Rails 6.2.

@katelovescode
Copy link

Bumping again as I have my gemfile pegged to @Vasfed 's fork on the rails6_warning branch.

@ctran ctran added the feature label Mar 24, 2021
@ctran ctran added this to the v4.0.0 milestone Mar 24, 2021
@ctran ctran modified the milestones: v4.0.0, Parking Lot Feb 1, 2022
@skv-headless
Copy link

@ctran please

8e4487c780adcc95ce856b305219c442

@ctran ctran self-assigned this Jun 24, 2022
@Vasfed Vasfed force-pushed the rails6_warning branch 2 times, most recently from 85ce415 to dba8ce9 Compare August 1, 2022 15:58
@Vasfed
Copy link
Contributor Author

Vasfed commented Aug 1, 2022

Rebased onto current develop, test seem to fail because of run order and not the changes

@ndbroadbent
Copy link
Contributor

ndbroadbent commented Nov 24, 2022

This works great for me! Not sure why the CI is failing. I also tried replacing rake routes with rails routes, and it works fine for me.

I prefer not to add forked gems to my Gemfile since they don't get updated by dependabot. So I just added a monkey patch for this method to lib/monkey_patches/annotate_routes.rb:

# frozen_string_literal: true

if Rails.env.development?
  if Annotate.version != '3.2.0'
    raise "annotate has been updated to version #{Annotate.version}! " \
      "Check if the 'rails routes' patch is still needed, or if this PR has been merged: " \
      'https://github.com/ctran/annotate_models/pull/843'
  end

  module AnnotateRoutes
    class HeaderGenerator
      class << self
        private

        # UPDATE: Changed `rake routes` to `rails routes`
        def routes_map(options)
          result = `rails routes`.chomp("\n").split(/\n/, -1)

          # In old versions of Rake, the first line of output was the cwd.  Not so
          # much in newer ones.  We ditch that line if it exists, and if not, we
          # keep the line around.
          result.shift if result.first =~ %r{^\(in /}

          ignore_routes = options[:ignore_routes]
          regexp_for_ignoring_routes = ignore_routes ? /#{ignore_routes}/ : nil

          # Skip routes which match given regex
          # Note: it matches the complete line (route_name, path, controller/action)
          if regexp_for_ignoring_routes
            result.reject { |line| line =~ regexp_for_ignoring_routes }
          else
            result
          end
        end
      end
    end
  end
end

@pboling
Copy link
Contributor

pboling commented Dec 8, 2022

Route annotation is broken until this is addressed @ctran ! How can the community help maintain this library? I've helped in the past (long, long ago, in a galaxy far away) and would be happy to help out again! I love this tool!

@ctran
Copy link
Owner

ctran commented Dec 9, 2022

I need help getting CI to work if you can spare some time. I was attempting to set up gitpod env but ran into few issues and haven't had time to continue.

@CoderMiguel
Copy link

I was able to add a task that solved this for me:

lib/tasks.routes.rake

task :routes do
  puts `bin/rails routes`
end

This injects the rails routes behavior into the rake implementation that the gem is currently looking for.

@G-Rath
Copy link

G-Rath commented Jan 1, 2024

@ctran looks like the CI issues have been resolved now so hopefully this is good to go - is there anything else that could be done to help you with shipping this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deprecation Warning on Rails 6.1 - bin/rake routes