Reputation: 981
File.open(File.join(__dir__, 'config/global_nav_data.yml'))
The rails project where my gem got installed will have some file inside config folder. I have to get that file in the project. I tried the above but it is fetching file in the gem not in the project .
Upvotes: 1
Views: 466
Reputation: 121000
File.open(File.join(Rails.root, 'config', 'global_nav_data.yml'))
One probably wants to add a check for Rails
is defined, like:
if Kernel.const_defined? 'Rails'
File.open(File.join(Rails.root, 'config', 'global_nav_data.yml'))
else
raise 'I need Rails to run!'
end
Upvotes: 2