Forum: Ruby on Rails Rails engines question

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Be07c8d0d6867fd9a0d525f7d17600e2?d=identicon&s=25 Damjan Rems (ther)
on 2013-03-08 23:27
I would like to use my own directory named forms inside my own engine. I
know I can add it to loading paths like this in application.rb
module MyAPP
  class Application < Rails::Application
    config.paths["forms"] = Rails.root.join('vendor/myapp/forms')
  end
end
or inside

and can access it inside controller like this:

  MyAPP::Application.config["forms"]

Which is a bit of a problem since my engine would have to know
application name inside which it runs. So, my questions are:

1. Is there a better way to access config object?. Like session or
params inside controller.

2. What Rails API method is used to search files for example in
MyAPP::Application.config["views"] paths and returns name of file (view)
if find.

by
TheR
Be07c8d0d6867fd9a0d525f7d17600e2?d=identicon&s=25 Damjan Rems (ther)
on 2013-03-09 11:12
I found it myself.

1. Rails.configuration.paths["forms"]

2. I did my own method for now.

def find_form_file(form)
  Rails.configuration.paths["forms"].each do |path|
    f = "#{path}/#{form}.yml"
    return f if File.exist?(f)
  end
  p "Form file #{form} not found!"
  nil
end


by
TheR
This topic is locked and can not be replied to.