librelist archives

« back to archive

Custom configuration vars | Nesta environment variable

Custom configuration vars | Nesta environment variable

From:
André
Date:
2014-05-23 @ 19:26
Hi!

I'm setting up a mailer in Nesta with Pony gem, works well but now that I
want to add sensitive information about the SMTP setup, passwords and such,
I would like to add them in the config.yml file which I will not commit
anywhere.

I've read http://nestacms.com/docs/config/environment-variables though I'm
not quite sure how to specifically reach my settings.

I presume I should be looking in ENV, such as:

ENV["NESTA_MAILER__PROTOCOL"]

returns nil

I don't seem to be able to reach any information at all from ENV, just
about Rack etc.

Logging ENV will give me a bunch of info, but after a while page breaks and
results in a type error:

TypeError: no implicit conversion of Array into String

Thanks for your help!

Re: [nesta] Custom configuration vars | Nesta environment variable

From:
Graham Ashton
Date:
2014-05-23 @ 19:38
On 23 May 2014, at 20:26, André <andre.drougge@gmail.com> wrote:

> I'm setting up a mailer in Nesta with Pony gem, works well but now that 
I want to add sensitive information about the SMTP setup, passwords and 
such, I would like to add them in the config.yml file which I will not 
commit anywhere.

The environment variable stuff you’ve been reading about is to enable you 
to configure Nesta by setting variables instead of editing the config. 
They’re not for reading the config file.

You can read settings with a bit of Ruby. Try something like this:

    Nesta::Config.fetch(‘your_key’)

You can pass a second argument that will be returned if the config setting
isn’t defined in config.yml.

> Logging ENV will give me a bunch of info, but after a while page breaks 
and results in a type error:
> 
> TypeError: no implicit conversion of Array into String

When you say “after a while” do you mean after repeated attempts to 
deliver email? There’s nothing in Nesta itself that I can think would give
you random errors like that.

If you still need help with that after your config is sorted, we’ll need 
access to your project. Either make a git repository publicly available, 
or add me (username gma) to a private repo on GitHub or Bitbucket and I’ll
take a look.

Also send the full stack trace that contains the TypeError message.

Cheers,
Graham

Re: [nesta] Custom configuration vars | Nesta environment variable

From:
André
Date:
2014-05-25 @ 20:21
Thanks Graham, I have now put all what I wanted in the config and I can
access them as I please.

The other problem turned out to be completely unrelated.

On another note, I have been looking into some kind of form-validation gem
for Sinatra and I found this gem
sinatra-formkeeper<https://github.com/lyokato/sinatra-formkeeper>
which
seemed very promising. I'm having some trouble with it though and was
wondering if you've done something similar with Nesta and had a better
suggestion?

This is my Boot error after adding the gem in gemfile and running bundle,
if needed.
https://gist.github.com/miphe/74fe0ff23af60f4db416

Thanks


2014-05-23 22:38 GMT+03:00 Graham Ashton <graham@effectif.com>:

> On 23 May 2014, at 20:26, André <andre.drougge@gmail.com> wrote:
>
> > I'm setting up a mailer in Nesta with Pony gem, works well but now that
> I want to add sensitive information about the SMTP setup, passwords and
> such, I would like to add them in the config.yml file which I will not
> commit anywhere.
>
> The environment variable stuff you’ve been reading about is to enable you
> to configure Nesta by setting variables instead of editing the config.
> They’re not for reading the config file.
>
> You can read settings with a bit of Ruby. Try something like this:
>
>     Nesta::Config.fetch(‘your_key’)
>
> You can pass a second argument that will be returned if the config setting
> isn’t defined in config.yml.
>
> > Logging ENV will give me a bunch of info, but after a while page breaks
> and results in a type error:
> >
> > TypeError: no implicit conversion of Array into String
>
> When you say “after a while” do you mean after repeated attempts to
> deliver email? There’s nothing in Nesta itself that I can think would give
> you random errors like that.
>
> If you still need help with that after your config is sorted, we’ll need
> access to your project. Either make a git repository publicly available, or
> add me (username gma) to a private repo on GitHub or Bitbucket and I’ll
> take a look.
>
> Also send the full stack trace that contains the TypeError message.
>
> Cheers,
> Graham
>



-- 
André Drougge
Web Developer
portfolio.miphe.com

Re: [nesta] Custom configuration vars | Nesta environment variable

From:
Graham Ashton
Date:
2014-05-26 @ 14:28
On 25 May 2014, at 21:21, André <andre.drougge@gmail.com> wrote:

> I found this gem sinatra-formkeeper which seemed very promising. I'm 
having some trouble with it though and was wondering if you've done 
something similar with Nesta and had a better suggestion?

I’m afraid not. I’d code up form validation myself, or if that seemed too 
hard I'd use Rails (plugging Nesta in to Rails to serve the web site).

> This is my Boot error after adding the gem in gemfile and running 
bundle, if needed.
> https://gist.github.com/miphe/74fe0ff23af60f4db416

I’m afraid I can’t really help you just from an error message. Send me 
code (for the entire project) and I’ll take a look, otherwise I’ll just be
guessing about what might have caused it.

I suspect you’ve not called the register method properly though, or in the
right context.

Re: [nesta] Custom configuration vars | Nesta environment variable

From:
André
Date:
2014-05-26 @ 16:26
Yes, I was considering if I'd need to write the validation myself. It's a
very tiny form so it shouldn't be too much of a bother, but if I can get
this gem to work that would be just perfect.

I've just committed what I was working on (wip) and if you can see where
I'm off wrong with the form keeper, that'd be very helpful. repo
here<https://github.com/miphe/mi6> ,
the form keeper require and register etc. are there but commented out since
they break the site atm.

Much appreciated!



2014-05-26 17:28 GMT+03:00 Graham Ashton <graham@effectif.com>:

> On 25 May 2014, at 21:21, André <andre.drougge@gmail.com> wrote:
>
> > I found this gem sinatra-formkeeper which seemed very promising. I'm
> having some trouble with it though and was wondering if you've done
> something similar with Nesta and had a better suggestion?
>
> I’m afraid not. I’d code up form validation myself, or if that seemed too
> hard I'd use Rails (plugging Nesta in to Rails to serve the web site).
>
> > This is my Boot error after adding the gem in gemfile and running
> bundle, if needed.
> > https://gist.github.com/miphe/74fe0ff23af60f4db416
>
> I’m afraid I can’t really help you just from an error message. Send me
> code (for the entire project) and I’ll take a look, otherwise I’ll just be
> guessing about what might have caused it.
>
> I suspect you’ve not called the register method properly though, or in the
> right context.
>



-- 
André Drougge
Web Developer
portfolio.miphe.com

Re: [nesta] Custom configuration vars | Nesta environment variable

From:
Graham Ashton
Date:
2014-05-27 @ 21:21
On 26 May 2014, at 17:26, André <andre.drougge@gmail.com> wrote:

> I've just committed what I was working on (wip) and if you can see where
I'm off wrong with the form keeper, that'd be very helpful. repo here , 
the form keeper require and register etc. are there but commented out 
since they break the site atm.

There’s no way I’d have worked this out if I hadn’t had the code.

The first place I looked was the bug tracker. There’s one open issue.

https://github.com/lyokato/sinatra-formkeeper/issues/2

@lyokato’s comment basically explains what’s wrong.

Bundler, in its infinite wisdom, has decided it ought to be responsible 
for requiring all our gems for us. This has never struck me as a sensible 
default, as writing explicit require statements isn’t exactly a chore, and
load order often matters.

When you add a gem to your Gemfile bundler will automatically try and load
it. In this case that’s bad news, as `sinatra/base` needs to be required 
first, or the `register` method won’t be defined yet.

Change your Gemfile so it pulls in the extension like this:

    gem 'sinatra-formkeeper', require: nil

Then add this to the top of your app.rb file:

    require ‘sinatra/formkeeper’

Nesta won’t load app.rb until after Sinatra has been loaded properly, and 
on my laptop this was enough to get your site up with the extension 
loaded.

Cheers,
Graham