Skip to content

Commit da03abc

Browse files
committed
Created Edit Users in signup form, added edit updated functionality and partials
1 parent f394c2b commit da03abc

File tree

4 files changed

+77
-56
lines changed

4 files changed

+77
-56
lines changed

app/controllers/users_controller.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ def create
1414
end
1515
end
1616

17+
def edit
18+
@user = User.find(params[:id])
19+
end
20+
21+
def update
22+
@user = User.find(params[:id])
23+
if @user.update(user_params)
24+
flash[:success] = "Your account has been updated successfully."
25+
redirect_to articles_path
26+
else
27+
render 'edit'
28+
end
29+
end
30+
1731
private
1832
def user_params
1933
params.require(:user).permit(:username, :email, :password)

app/views/users/_form.html.erb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<%= render 'shared/errors', obj: @user %>
2+
3+
4+
<div class='row'>
5+
<div class= 'col-xs-12'>
6+
<%= form_for(@user, :html => {class: "form-horizontal", role: "form"}) do |f| %>
7+
8+
<div class="form-group">
9+
<div class="control-label col-sm-2" >
10+
<%= f.label :username %>
11+
</div>
12+
<div class="col-sm-8">
13+
<%= f.text_field :username, class: "form-control", placeholder: "Enter a username", autofocus: true %>
14+
</div>
15+
</div>
16+
17+
18+
<div class="form-group" style="height:80px;">
19+
<div class="control-label col-sm-2">
20+
<%= f.label :email %>
21+
</div>
22+
<div class="col-sm-8">
23+
<%= f.email_field :email, class: "form-control", placeholder: "Enter your email address" %>
24+
</div>
25+
</div>
26+
27+
28+
<div class="form-group" style="height:60px;">
29+
<div class="control-label col-sm-2">
30+
<%= f.label :password %>
31+
</div>
32+
<div class="col-sm-8">
33+
<%= f.password_field :password, class: "form-control", placeholder: "Enter your password" %>
34+
</div>
35+
</div>
36+
37+
38+
39+
<div class="form-group">
40+
<div class="col-sm-offset-2 col-sm-10">
41+
<%= f.submit(@user.new_record? ? "SIGN-UP" : "UPDATE ACCOUNT", class: 'btn btn-primary btn-lg') %>
42+
</div>
43+
</div>
44+
<% end %>
45+
46+
<br/>
47+
48+
49+
<div class="col-xs-4 col-xs-offset-4">
50+
[ <%= link_to "Cancel request and returns to articles listing", articles_path %> ]
51+
</div>
52+
</div>
53+
</div>
54+

app/views/users/edit.html.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h1 align="center">
2+
Edit your Account
3+
</h1>
4+
5+
<br/>
6+
<%= render 'form' %>
7+

app/views/users/new.html.erb

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,6 @@
1-
<h1 align="center">SignUp For Alpha Tech Blog: </h1>
1+
<h1 align="center">Sign-Up For Alpha Tech Blog: </h1>
22
<br/>
33
<br/>
44

5-
<%= render 'shared/errors', obj: @user %>
6-
7-
8-
<div class='row'>
9-
<div class= 'col-xs-12'>
10-
<%= form_for(@user, :html => {class: "form-horizontal", role: "form"}) do |f| %>
11-
12-
<div class="form-group">
13-
<div class="control-label col-sm-2" >
14-
<%= f.label :username %>
15-
</div>
16-
<div class="col-sm-8">
17-
<%= f.text_field :username, class: "form-control", placeholder: "Enter a username", autofocus: true %>
18-
</div>
19-
</div>
20-
21-
22-
<div class="form-group" style="height:80px;">
23-
<div class="control-label col-sm-2">
24-
<%= f.label :email %>
25-
</div>
26-
<div class="col-sm-8">
27-
<%= f.email_field :email, class: "form-control", placeholder: "Enter your email address" %>
28-
</div>
29-
</div>
30-
31-
32-
<div class="form-group" style="height:80px;">
33-
<div class="control-label col-sm-2">
34-
<%= f.label :password %>
35-
</div>
36-
<div class="col-sm-8">
37-
<%= f.password_field :password, class: "form-control", placeholder: "Enter your password" %>
38-
</div>
39-
</div>
40-
41-
42-
43-
<div class="form-group">
44-
<div class="col-sm-offset-2 col-sm-10">
45-
<%= f.submit "SIGN-UP", class: 'btn btn-primary btn-lg' %>
46-
</div>
47-
</div>
48-
<% end %>
49-
50-
<br/>
51-
52-
53-
<div class="col-xs-4 col-xs-offset-4">
54-
[ <%= link_to "Cancel request and returns to articles listing", articles_path %> ]
55-
</div>
56-
</div>
57-
</div>
58-
59-
5+
<%= render 'form' %>
606

0 commit comments

Comments
 (0)