librelist archives

« back to archive

Nesta contact form for complete Sinatra newbie

Nesta contact form for complete Sinatra newbie

From:
Jake Subs
Date:
2012-02-17 @ 14:54
I'd like to have a simple contact form on my contact.haml page. From
this list, I found this tutorial:
http://ididitmyway.heroku.com/past/2010/12/4/an_email_contact_form_in_sinatra/

But as my knowledge of Nesta/Sinatra/Ruby is immensely limited, I have
some very basic questions:

1. The handler. This is:
    get '/contact' do
      erb :contact
    end
I presume it's saved in /themes/jaketheme/views but what should its
name be, and do you change the above to `haml :contact`?

2. The contact page itself. I already have a
/content/pages/contact.haml -- do I move it to /themes/jaketheme/views
?

That's pretty much it for starters! Apologies for my total lack of
knowledge, I've skim read Sinatra Up and Running http://ow.ly/98ecq
and I'm planning a return visit, plus plan to start with Learn Ruby
The Hard Way http://ruby.learncodethehardway.org/

many thanks, Jake

PS my existing contact form is up on github:
https://github.com/growdigital/jrayson/blob/master/content/pages/contact.haml

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
Graham Ashton
Date:
2012-02-17 @ 16:04
On 17 Feb 2012, at 14:54, Jake Subs wrote:

> I'd like to have a simple contact form on my contact.haml page. From
> this list, I found this tutorial:
> http://ididitmyway.heroku.com/past/2010/12/4/an_email_contact_form_in_sinatra/

I'd take the Sendgrid option of the two; I wouldn't fancy putting my gmail
password in an easily accessible file on a web server (even if I'd done 
the firewall myself, it's a bit risky).

> But as my knowledge of Nesta/Sinatra/Ruby is immensely limited, I have
> some very basic questions:
> 
> 1. The handler. This is:
>    get '/contact' do
>      erb :contact
>    end
> I presume it's saved in /themes/jaketheme/views but what should its
> name be, and do you change the above to `haml :contact`?

If you were using pure Sinatra, yes to both questions. Anything that works
in Sinatra also works in Nesta, but...

> 2. The contact page itself. I already have a
> /content/pages/contact.haml -- do I move it to /themes/jaketheme/views
> ?

No. The code that starts with `get '/contact'` is telling Sinatra what to 
do when somebody visits /contact on your site. But Nesta already knows to 
check in content/pages.

So if you drop the form in a Haml file at content/pages/contact.haml then 
you'll be able to skip the `get...` bit, as Nesta automates the addition 
of the `get '/contact'` code for you.

You'll need to add the post handler in an app.rb file though.

> That's pretty much it for starters! Apologies for my total lack of
> knowledge, I've skim read Sinatra Up and Running http://ow.ly/98ecq
> and I'm planning a return visit, plus plan to start with Learn Ruby
> The Hard Way http://ruby.learncodethehardway.org/

An excellent start. With repeated reading, playing around, head 
scratching, and more reading, it should all come together rather 
quickly...

--
Graham Ashton
Founder, The Agile Planner
http://theagileplanner.com | @agileplanner | @grahamashton

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
hectorsq
Date:
2012-02-17 @ 19:30
Jake,

Have a look at this repository:

https://github.com/virtus/mundoreal-site

And this specific file:

https://github.com/virtus/mundoreal-site/blob/master/themes/mundoreal/app.rb

I do not know if this is the best way, but it is working fine for me on
heroku.

Regards,
Hector Sansores

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
David Long
Date:
2012-02-17 @ 19:36
That's exactly how I have my site setup on Heroku. You probably don't need
the get 'success' route though.  Just drop a success.haml in the root of 
our content/pages directory and the /success route will work anyways. 
Leave in your redirect though. 


Dave Long
Web Application Consultant

(203) 626-1809
www.davejlong.com (http://www.davejlong.com)


Sent with Sparrow (http://www.sparrowmailapp.com/?sig)


On Friday, February 17, 2012 at 2:30 PM, hectorsq wrote:

> Jake,
> 
> Have a look at this repository:
> 
> https://github.com/virtus/mundoreal-site
> 
> And this specific file: 
> 
> https://github.com/virtus/mundoreal-site/blob/master/themes/mundoreal/app.rb
> 
> I do not know if this is the best way, but it is working fine for me on heroku. 
> 
> Regards,
> Hector Sansores
> 

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
Jake Subs
Date:
2012-02-20 @ 20:16
Hector,

On 17 February 2012 19:30, hectorsq <mail@hectorsq.com> wrote:
> Have a look at this repository:
> https://github.com/virtus/mundoreal-site

It's in spanish but somehow makes a lot of sense ;) Thanks for the
info, will give it a go now.

-- 
[~] Jake Rayson
[w] www.jrayson.co.uk
[e] subs@growdigital.org
[t] @growdigital

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
Jake Subs
Date:
2012-02-20 @ 20:18
On 17 February 2012 16:04, Graham Ashton <graham@effectif.com> wrote:
> No. The code that starts with `get '/contact'` is telling Sinatra what 
to do when somebody visits /contact on your site. But Nesta already knows 
to check in content/pages.
> So if you drop the form in a Haml file at content/pages/contact.haml 
then you'll be able to skip the `get...` bit, as Nesta automates the 
addition of the `get '/contact'` code for you.
> You'll need to add the post handler in an app.rb file though.

Excellent, starting to make sense now. Thanks :)

-- 
[~] Jake Rayson
[w] www.jrayson.co.uk
[e] subs@growdigital.org
[t] @growdigital

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
Jake Subs
Date:
2012-02-20 @ 20:57
I feel like I'm making progress even though I don't have much to show.

> On 17 February 2012 16:04, Graham Ashton <graham@effectif.com> wrote:
>> You'll need to add the post handler in an app.rb file though.

1. I have installed the Pony gem with `gem install pony`. Doesn't show
up when I run `bundle install` though -- should it?

2. I have `contact.haml` in the `content/pages/` directory, replete
with form, plus success.haml replete with heading.

3. I have added the I Did It His Way code to app.rb in
`/themes/jaketheme/`, just below `class App`:

    post '/contact' do
      require 'pony'
       Pony.mail(
        :from => params[:name] + "<" + params[:email] + ">",
        :to => 'iam@jrayson.co.uk',
        :subject => params[:name] + " has contacted you",
        :body => params[:message],
        :port => '587',
        :via => :smtp,
        :via_options => {
          :address              => 'smtp.sendgrid.net',
          :port                 => '587',
          :enable_starttls_auto => true,
          :user_name            => ENV['SENDGRID_USERNAME'],
          :password             => ENV['SENDGRID_PASSWORD'],
          :authentication       => :plain,
          :domain               => ENV['SENDGRID_DOMAIN']
        })
      redirect '/success'
    end

First error I get on submitting the form is:
    LoadError at /contact
    cannot load such file -- pony

If I put `require 'pony'` at top of app.rb, then this error is no
more, to be replaced with a page not found.

Thanks again for everybody's help, very much appreciated.

I've pushed the code up to GitHub but not pushed it live, for kind of
obvious reasons. One day I will learn how to set up a test branch and
subdomain!

cheers, Jake

-- 
[~] Jake Rayson
[w] www.jrayson.co.uk
[e] subs@growdigital.org
[t] @growdigital

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
hectorsq
Date:
2012-02-21 @ 04:22
Jake,

It seems that you need to add pony in your Gemfile.

https://github.com/virtus/mundoreal-site/blob/master/Gemfile

Then run bundlle to update Gemfile.lock

Try it, and let me know if it worked.

Regards,
Hector

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
Jake Subs
Date:
2012-02-21 @ 12:17
On 21 February 2012 04:22, hectorsq <mail@hectorsq.com> wrote:
> It seems that you need to add pony in your Gemfile.
> https://github.com/virtus/mundoreal-site/blob/master/Gemfile
> Then run bundlle to update Gemfile.lock

That works a treat, I was wondering how to add a gem.

The next error I get is:
    NoMethodError at /contact
    undefined method `+' for nil:NilClass
    :subject => params[:name] + " has contacted you"

This is easily fixed by simply removing `+ " has contacted you"

And then the error I get is:
    Net::SMTPFatalError at /contact
    550 Cannot receive from specified address <pony@unknown>:
Unauthenticated senders not allowed
    file: smtp.rb location: check_response line: 948

These are my settings in app.rb:
    :address              => 'smtp.sendgrid.net',
    :port                 => '587',
    :enable_starttls_auto => true,
    :user_name            => ENV['SENDGRID_USERNAME'],
    :password             => ENV['SENDGRID_PASSWORD'],
    :authentication       => :plain,
    :domain               => ENV['SENDGRID_DOMAIN']

I have tried entering my sendgrid username & password & my domain, all
to no avail.
https://github.com/growdigital/jrayson/blob/master/themes/jaketheme/app.rb

Will keep looking for a solution :)

Thanks for your help, Jake

-- 
[~] Jake Rayson
[w] www.jrayson.co.uk
[e] subs@growdigital.org
[t] @growdigital

Re: [nesta] Nesta contact form for complete Sinatra newbie

From:
Eric Flecher
Date:
2012-02-20 @ 20:53
Please remove me from the mailing list.

Thanks,
Eric

On Fri, Feb 17, 2012 at 8:54 AM, Jake Subs <subs@growdigital.org> wrote:

> I'd like to have a simple contact form on my contact.haml page. From
> this list, I found this tutorial:
>
> http://ididitmyway.heroku.com/past/2010/12/4/an_email_contact_form_in_sinatra/
>
> But as my knowledge of Nesta/Sinatra/Ruby is immensely limited, I have
> some very basic questions:
>
> 1. The handler. This is:
>    get '/contact' do
>      erb :contact
>    end
> I presume it's saved in /themes/jaketheme/views but what should its
> name be, and do you change the above to `haml :contact`?
>
> 2. The contact page itself. I already have a
> /content/pages/contact.haml -- do I move it to /themes/jaketheme/views
> ?
>
> That's pretty much it for starters! Apologies for my total lack of
> knowledge, I've skim read Sinatra Up and Running http://ow.ly/98ecq
> and I'm planning a return visit, plus plan to start with Learn Ruby
> The Hard Way http://ruby.learncodethehardway.org/
>
> many thanks, Jake
>
> PS my existing contact form is up on github:
>
> https://github.com/growdigital/jrayson/blob/master/content/pages/contact.haml
>



-- 
*Eric Flecher*
*Technical Manager**
*
*eric.flecher@saggezza.com
*(800) 460-5912
*
Saggezza  |  www.saggezza.com
*200 W Madison  |  Suite 1800  |  Chicago, IL 60606
*This message is for the designated recipient only and may contain
privileged or confidential information. If you have received it in error,
please notify the sender immediately and delete the original. Any other use
of the email by you is prohibited.
Go Green!  Please do not print this e-mail unless it is necessary*