Sylar Sylar - 4 months ago 13
Ruby Question

Path to a root file in controller


  1. Can you store a
    .pem
    as an environment variable? If so, how?

  2. How can I access my
    .pem
    from from the controller?



Controller:

before_filter :some_method

def show
@some_var = @data
end

private
def some_method
@data = Some::PrivateApplication.new(ENV['KEY1'], "../../secret.pem")
end


Views:

<%= @som_var.SOMECONST.some_other_method %>



No such file or directory @ rb_sysopen - ../../secret.pem

Answer

You can use the hash ENV for environment variables, e.g.

ENV['SECRET_PEM_FILE']

To find the path relative to your application, try Rails.root, e.g.

"#{Rails.root}/config/secret.pem"

...but don't put the key in version control!

Comments