I am working on a rails engine and I am trying to write a generator that will put this line
do_stuff (foo)
as the last statement in config/routes.rb
, without breaking the file syntax.
Specifically, if my config/routes.rb
looks like this currently
Rails.application.routes.draw do
blah
more blah
end
After running the generator I would like the config/routes.rb
to look like this
Rails.application.routes.draw do
blah
more blah
do_stuff (foo) # injected line
end
I looked at what ActiveAdmin does, but am unable to create a blanket last line rule. Any help is greatly appreciated.
i did not test that out, but i think from what you linked to in the ActiveAdmin generator it might work like this:
inject_into_file "config/routes.rb", " do_stuff(foo)\n", :before => /^end/
this should insert your code right before an end
token that starts at the beginning of a line. this only works for properly formatted routes files though....
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With