Permalink
Browse files

finish user signup

  • Loading branch information...
1 parent 757600f commit 7be32299f980169f0b2179ea1e8c82fb22d1cf30 Hakim Hanif committed May 20, 2014
@@ -151,3 +151,16 @@ aside {
margin-right: 10px;
}
+#error_explanation {
+ color: #f00;
+ ul {
+ list-style: none;
+ margin: 0 0 18px 0;
+ }
+}
+
+.field_with_errors {
+ @extend .control-group;
+ @extend .error;
+}
+
@@ -1,8 +1,26 @@
class UsersController < ApplicationController
def new
+ @user = User.new
+ end
+
+ def create
+ @user = User.new ( user_params )
+ if @user.save
+ flash[:success]="Welcome to the Sample App"
+ redirect_to @user
+ else
+ render "new"
+ end
end
def show
@user = User.find( params[:id] )
end
+
+ private
+
+ def user_params
+ params.require(:user).permit(:name, :email, :password,
+ :password_confirmation)
+ end
end
@@ -11,6 +11,9 @@
<body>
<%= render 'layouts/header' %>
<div class="container">
+ <% flash.each do |key, value| %>
+ <div class="alert alert-<%= key %>"><%= value %></div>
+ <% end %>
<%= yield %>
<%= render 'layouts/footer' %>
<%= debug(params) if Rails.env.development? %>
@@ -0,0 +1,12 @@
+<% if @user.errors.any? %>
+ <div id="error_explanation">
+ <div class="alert alert-error">
+ The form contains <%= pluralize(@user.errors.count, "error") %>.
+ </div>
+ <ul>
+ <% @user.errors.full_messages.each do |msg| %>
+ <li>* <%= msg %></li>
+ <% end %>
+ </ul>
+ </div>
+<% end %>
@@ -1,3 +1,24 @@
<% provide(:title, 'Sign up') %>
<h1>Sign up</h1>
-<p>Find me in app/views/users/new.html.erb</p>
+
+<div class="row">
+ <div class="span6 offset3">
+ <%= form_for(@user) do |f| %>
+ <%= render 'shared/error_messages' %>
+
+ <%= f.label :name %>
+ <%= f.text_field :name %>
+
+ <%= f.label :email %>
+ <%= f.text_field :email %>
+
+ <%= f.label :password %>
+ <%= f.password_field :password %>
+
+ <%= f.label :password_confirmation, "Confirmation" %>
+ <%= f.password_field :password_confirmation %>
+
+ <%= f.submit "Create my account", class: "btn btn-large btn-primary" %>
+ <% end %>
+ </div>
+</div>
@@ -22,10 +22,13 @@
end
describe "signup" do
- before { visit signup_path}
+ before { visit signup_path}
+ let (:submit) { "Create my account" }
describe "with invalid information" do
- expect { click_button "Create my account"}.not_to change(User, :count)
+ it "should not create a new user" do
+ expect { click_button submit}.not_to change(User, :count)
+ end
end
describe "with valid information" do
@@ -37,7 +40,7 @@
end
it "should create a user" do
expect { click_button submit }.to change(User, :count).by(1)
- end
+ end
end
end

0 comments on commit 7be3229

Please sign in to comment.