Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class User < ActiveRecord::Base
- attr_accessible :email, :name, :password, :username
- validates_presence_of :email, :name, :password, :username
- end
- class SignupController < ApplicationController
- def init
- @user = User.new
- render :template => '/signup/signup'
- end
- def signup
- @user = User.new(params[:user])
- if @user.valid?
- @user.save
- render :template => '/signup/success'
- else
- #bla bla bla
- end
- end
- end
- <h1>Signup!!!</h1>
- <%= form_for(@user, :url => signup_path) do |f| %>
- Name: <%= f.text_field :name %> </br>
- Email <%= f.text_field :email %> </br>
- Username: <%= f.text_field :username %> </br>
- Password: <%= f.text_field :password %> </br>
- <%= submit_tag "Submit" %>
- <% end %>
- <h1>signup successfull :) </h1>
- get '/index/signup' => 'signup#init', :as => :signup_index
- post '/index/signup/' => 'signup#signup', :as => :signup
- gem 'strong_parameters'
- class User < ActiveRecord::Base
- include ActiveModel::ForbiddenAttributesProtection
- validates_presence_of :email, :name, :password, :username
- end
- class UsersController < ApplicationController
- def new
- @user = User.new
- end
- def create
- @user = User.new(user_params)
- if @user.save
- redirect_to login_path, :notice => "You have signed up successfully. You may now login!"
- else
- render :new, :alert => "There was an problem creating your account"
- end
- end
- private
- def user_params
- params.require(:user).permit(:email, :name, :password, :username)
- end
- end
- <h1>Signup!!</h1>
- <%= render :partial => "form" %>
- <%= form_for @user do |f| %>
- <%= f.label :name %>
- <%= f.text_field :name %><br />
- <%= f.label :email, "Email Address" %>
- <%= f.email_field :email %><br />
- <%= f.label :username %>
- <%= f.text_field :username %><br />
- <%= f.label :password %>
- <%= f.password_field :password %><br />
- <%= f.submit "Sign Up" %>
- <% end %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement