You’re not receiving notifications from this thread.
Simple newsletter sign up?
Hey Chris and all other members of this forum....
I'm trying to create a single page rails site, for a new app that i'm trying to build myself (it's called Nibli, and it's on nibliapp.com).
I've been scouting the net everywhere to get some information on building a newsletter signup form on the home page i.e. to store data in a database that can be accessed by me later with details like - name, email, device (i.e. iPhone or Android) and country... However i have no clue where to start in building this controller and model for the newsletter (which is what i'm assuming i would need to do).
I don't want it to link to mail chimp, i'd like it to have a local database on the server from which i can get this info.... for later use.
Cheers for any help in advance
Great little project. Maybe I can record a screencast for this over the weekend. The gist of it is going to be really simple:
- You'll have a model called
Leador something like that. It will have columns for the attributes you want to store:
- You'll set up a
LeadsControllerthat can have the
createaction to save the Lead and renders a response.
- On the action that displays the homepage (I'll just call this LeadsController#index for now), you would create a
<%= form_for @lead, remote: true do |f| %>and in the controller, you would set
@lead = Lead.new.
- An optional piece here is the
- That's pretty much it. You will probably want to store a cookie after create so that the next time the user visits the site again, they don't see the lead form twice.
You'll also need something to auto-detect the device probably unless you want the user to select it in the form. Something like this Browser gem might be helpful.
It's really not too hard, but it can be a lot to wrap your head around. This would make for a great screencast though, so I'll be sure to record a version of how to do this soon.
What parts here seem the most daunting?
Awesome that you replied to this so quick :)
To be honest, everything about this seems daunting haha. I've done the one month rails course, but i still seem to hit a brick wall and go completely blank when ever i'm trying to get into a new app in rails... It's the same for another app that i'm working on (which is purely web based).
For the device option, I think i would prefer like a dropdown with the two devices listed that the user can select (same as for the country i.e. dropdown with all countries listed) .
A screen cast for this would be wicked! i've got the html and css for this page all done, but it's just this little piece of work that's kicking my ass!
Cheers again for the quick reply and the offer of a screen cast :)
Alright, I got an episode recorded for you! http://videos.gorails.com/medias/4h3x4wsnhp
Give it a watch and see what you think. I'm curious how you feel about the speed of the episode. I touched on a lot of things all at once but tried to break them down just enough. Hopefully you'll find it useful!
I think I'll try releasing this out as a full GoRails episode as well and see what people think.
Hey Chris... I've watched the video and it's awesome, just what i was looking for... and couldn't see any where online to do it.
I'm going to watch the video again and then put it into practice.
Thanks again for creating this video, you're a legend!
Nice video, glad Gareth got some help. I like the idea of storing the cookie to hide the form. Not foolproof but definitely better than being prompted to sign up again. Awesome!
So i went through the video over the weekend, and i thought i had got it sussed out... however i find that when i submit my form nothing saves in the database.... locally or on my heroku test site....
It seems as though when i submit the form, i get a long link in the address bar i.e.
this happens locally as well
Perhaps you can give a bit of feed back see links below, any would be much appreciated (but not limited to Chris, I know there are some other very switched on guys on this forum :) )
I've installed activeadmin without devise, you can check out the leads on there as well:
Again any help would be much appreciated...
That would happen from missing the
method: "POST" parameter in your
$.ajax call. When a form is submitted via GET, it sends all the fields over in the URL instead of in the body.
If you make sure that it's sending a POST through, then you should be set.
Off topic sort of Gareth. It looks like your assets aren't being served up on your pages
index.html.erb. Good practice is to put your images into
appname/app/assets/images' then simply serve them in your view as<%= image_tag 'yourimage.png' %>
. Right now it looks like you're trying to serve them out of/public` but I think your syntax in the view might be incorrect. Just an observation. Hope you get your site worked out.
Thanks for the headsup re the images James...
I've figured it out... my button for submit, was just ----
div class="col-md-offset-4 col-md-4 formspace">
button type="submit" class="btn btn-primary btn-lg">Submit
instead of -----
div class="col-md-offset-4 col-md-4 formspace">
%= f.submit 'Submit'%>
It's amazing what how such a simple thing can ruin everything else haha
Cheers for the video again....
Actually chris... that wasn't the issue.. urgh! but i did figure out what was the problem....
the - <%= form_for @lead do |f| %> needed to be outside of the form divs i.e. before (form class="form-horizontal center")
does that make sense... anyway i've got it working now.... phew!!! So enough harassment from me, for now haha
Yup, looks like you are saving to database now. Glad you got it working. I just signed up myself on your app to test. ActiveAdmin shows my lead.
Your assets are still an issue so I'm not sure if you re-deployed with the proper code or not. If you get stuck, let me know.
It's all down to you and James :) so thanks a bunch...
I'm just stuck with two things now, getting it on digital ocean, which I'm trying to figure out through your deploy guide, and why my Nibli logo isn't playing nicely and being responsive... Grrr :)
Getting it on Digital Ocean is easy. I can walk you through it. The GoRails deploy guide should give you everything you need to get started. Let us know where you're stuck and we'll chime in to get you all setup.