Reputation: 4299
How would I be able to make a signup page with ruby on rails?
Like, I have a beta page and a user enters their email address and then I can add it to the database.
Also, I could send them an email confirming their signup
EDIT: I want something real simple. Like, just plain adding a row in a database simple. I don't need a password box and a username box because that just further complicates things. I'm a beginner so I like to have things simple.
Upvotes: 10
Views: 6591
Reputation: 376
I made an app for this. Launchrock offers a good solution, but if you have two types of users then you are hosed. Our future site will have multiple types of users and we wanted to record which type they were. So we made an app and it's on Github for the world to use and change. :D Fork and clone the repo to make it your own. I included social plugin's as well. It's not styled and you'll have to change a few things to fit your needs, but I tried to make note of those in the README.rd.
Upvotes: 1
Reputation: 80051
At the terminal:
$ rails new foobar
$ rm public/index.html
$ git init
$ git commit -m "Initial commit"
$ rails g scaffold subscription email:string
Open up your editor:
# app/models/subscription.rb
class Subscription < ActiveRecord::Base
validates :email, :presence => true # optionally validate format of email
end
# app/controllers/subscriptions_controller.rb
class SubscriptionsController < ApplicationController
def new
@subscription = Subscription.new
end
def create
@subscription = Subscription.new params[:subscription]
if @subscription.save
# queue a task to send a confirmation email (see below)
Resque.enqueue(SendConfirmationEmail, @subscription.email)
redirect_to root_path, :notice => 'Thanks for signing up.'
else
render :new
end
end
end
You can delete all of the other methods/actions from your SubscriptionsController, and you can cleanup routes.rb
by restricting the actions available on the subscriptions
resource with resources :subscriptions, :only => [:new, :create]
.
This doesn't really cover how to send the email. There are a lot of ways to do it, and the best practice is to not send it in the request/response flow for performance/responsiveness. I've got a line in there queuing a Resque job to do it, but you could easily add DelayedJob or another deferred/async process tool there instead.
Upvotes: 9
Reputation: 87416
This is the kind of thing that is very easy to do in Rails and you shouldn't need any extra gems. Here are the steps you will need to do:
<form method="POST">...</form>
) that contains a text box (<input type="text" .../>
) in it and a submit button (<input type="submit" />
). Rails has all sorts of helper methods that will help you make those HTML tags, but you don't have to use them if you don't want to.The action can be very simple:
def create_signup
Signups.create! :email => params[:email]
end
Does this make sense? Now that I have given you the general guide, you should be able to ask new questions that are more focussed on specific parts that you don't know how to do. You should also search the web because there are probably tutorials available for all of these steps.
Upvotes: 5
Reputation: 49713
This question is too broad to answer with the code itself, but here are some great links to point you in the right direction:
Devise (most common Rails auth & signup plugin):
https://github.com/plataformatec/devise
Devise tutorial:
http://railscasts.com/episodes/209-introducing-devise
Mailer tutorial:
http://railscasts.com/episodes/206-action-mailer-in-rails-3
Other Auth tutorials:
http://railscasts.com/episodes/250-authentication-from-scratch
http://railscasts.com/episodes/270-authentication-in-rails-3-1
Upvotes: 1
Reputation: 24236
You could have a look at the 'Devise' gem -
https://github.com/plataformatec/devise
Railscasts episode on 'Devise'
http://railscasts.com/episodes/209-introducing-devise
The excellent 'Rails Tutorial' also takes you through building a sign-up/authentication system from scratch -
http://ruby.railstutorial.org/ruby-on-rails-tutorial-book
Upvotes: 0