Skip to content

Commit dce321c

Browse files
committed
added views
1 parent 35cd89e commit dce321c

34 files changed

+650
-57
lines changed
+60-14
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,75 @@
11
class ProjectsController < ApplicationController
2-
before_action :authenticate_user!
3-
def index
4-
end
2+
before_action :authenticate_user!
3+
before_action :set_project, only: [:show, :edit, :update, :destroy]
54

6-
def show
7-
end
5+
# GET /projects
6+
# GET /projects.json
7+
def index
8+
@projects = Project.all
9+
end
810

9-
def new
10-
end
11+
# GET /projects/1
12+
# GET /projects/1.json
13+
def show
14+
end
1115

12-
def create
13-
end
16+
# GET /projects/new
17+
def new
18+
@project = Project.new
19+
end
1420

15-
def edit
21+
# GET /projects/1/edit
22+
def edit
23+
end
24+
25+
# POST /projects
26+
# POST /projects.json
27+
def create
28+
@project = Project.new(project_params)
29+
30+
respond_to do |format|
31+
if @project.save
32+
format.html { redirect_to @project, notice: 'Project was successfully created.' }
33+
format.json { render :show, status: :created, location: @project }
34+
else
35+
format.html { render :new }
36+
format.json { render json: @project.errors, status: :unprocessable_entity }
37+
end
1638
end
39+
end
1740

18-
def update
41+
# PATCH/PUT /projects/1
42+
# PATCH/PUT /projects/1.json
43+
def update
44+
respond_to do |format|
45+
if @project.update(project_params)
46+
format.html { redirect_to @project, notice: 'Project was successfully updated.' }
47+
format.json { render :show, status: :ok, location: @project }
48+
else
49+
format.html { render :edit }
50+
format.json { render json: @project.errors, status: :unprocessable_entity }
51+
end
1952
end
53+
end
2054

21-
def destroy
55+
# DELETE /projects/1
56+
# DELETE /projects/1.json
57+
def destroy
58+
@project.destroy
59+
respond_to do |format|
60+
format.html { redirect_to projects_url, notice: 'Project was successfully destroyed.' }
61+
format.json { head :no_content }
2262
end
63+
end
2364

24-
private
65+
private
66+
# Use callbacks to share common setup or constraints between actions.
67+
def set_project
68+
@project = Project.find(params[:id])
69+
end
2570

71+
# Never trust parameters from the scary internet, only allow the white list through.
2672
def project_params
27-
params.require(:projecs).permit(:name, :description, :contact_person_details)
73+
params.require(:project).permit(:name, :description, :contact_person_details, :user_id)
2874
end
2975
end

app/controllers/sites_controller.rb

+61-15
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,75 @@
11
class SitesController < ApplicationController
2-
before_action :authenticate_user!
3-
def index
4-
end
2+
before_action :authenticate_user!
3+
before_action :set_site, only: [:show, :edit, :update, :destroy]
54

6-
def show
7-
end
5+
# GET /sites
6+
# GET /sites.json
7+
def index
8+
@sites = Site.all
9+
end
810

9-
def new
10-
end
11+
# GET /sites/1
12+
# GET /sites/1.json
13+
def show
14+
end
1115

12-
def create
13-
end
16+
# GET /sites/new
17+
def new
18+
@site = Site.new
19+
end
1420

15-
def edit
21+
# GET /sites/1/edit
22+
def edit
23+
end
24+
25+
# POST /sites
26+
# POST /sites.json
27+
def create
28+
@site = Site.new(site_params)
29+
30+
respond_to do |format|
31+
if @site.save
32+
format.html { redirect_to @site, notice: 'Site was successfully created.' }
33+
format.json { render :show, status: :created, location: @site }
34+
else
35+
format.html { render :new }
36+
format.json { render json: @site.errors, status: :unprocessable_entity }
37+
end
1638
end
39+
end
1740

18-
def update
41+
# PATCH/PUT /sites/1
42+
# PATCH/PUT /sites/1.json
43+
def update
44+
respond_to do |format|
45+
if @site.update(site_params)
46+
format.html { redirect_to @site, notice: 'Site was successfully updated.' }
47+
format.json { render :show, status: :ok, location: @site }
48+
else
49+
format.html { render :edit }
50+
format.json { render json: @site.errors, status: :unprocessable_entity }
51+
end
1952
end
53+
end
2054

21-
def destroy
55+
# DELETE /sites/1
56+
# DELETE /sites/1.json
57+
def destroy
58+
@site.destroy
59+
respond_to do |format|
60+
format.html { redirect_to sites_url, notice: 'Site was successfully destroyed.' }
61+
format.json { head :no_content }
2262
end
63+
end
2364

24-
private
65+
private
66+
# Use callbacks to share common setup or constraints between actions.
67+
def set_site
68+
@site = Site.find(params[:id])
69+
end
2570

26-
def sites_params
27-
params.require(:sites).permit(:title, :link)
71+
# Never trust parameters from the scary internet, only allow the white list through.
72+
def site_params
73+
params.require(:site).permit(:title, :link, :description, :user_id, :project_id)
2874
end
2975
end

app/controllers/users_controller.rb

+32-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,41 @@
11
class UsersController < ApplicationController
2-
before_action :authenticate_user!
2+
before_action :authenticate_user!
3+
before_action :set_user, only: [:show, :edit, :update]
4+
5+
# GET /users/1/edit
6+
def edit
7+
end
8+
9+
def show
10+
end
311

4-
def edit
5-
end
612

7-
def update
13+
# PATCH/PUT /users/1
14+
# PATCH/PUT /users/1.json
15+
def update
16+
respond_to do |format|
17+
if @user.update(user_params)
18+
format.html { redirect_to @user, notice: 'User was successfully updated.' }
19+
format.json { render :show, status: :ok, location: @user }
20+
else
21+
format.html { render :edit }
22+
format.json { render json: @user.errors, status: :unprocessable_entity }
23+
end
824
end
25+
end
926

10-
private
1127

28+
private
29+
# Use callbacks to share common setup or constraints between actions.
30+
def set_user
31+
puts params[:id]
32+
@user = User.find(params[:id])
33+
puts @user
34+
end
35+
36+
# Never trust parameters from the scary internet, only allow the white list through.
1237
def user_params
13-
params.require(:user).permit(:first_name, :last_name, :email, :company_name)
38+
params.require(:user).permit(:first_name, :last_name, :email, :company_name)
1439
end
40+
1541
end
+8-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
<h2>Sign up</h2>
1+
<div class="col-md-8">
2+
<h2>Sign up</h2>
23

34
<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
45
<%= render "devise/shared/error_messages", resource: resource %>
56

67
<div class="field">
78
<%= f.label :email %><br />
8-
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
9+
<%= f.email_field :email, class: 'form-control', autofocus: true, autocomplete: "email" %>
910
</div>
1011

1112
<div class="field">
1213
<%= f.label :password %>
1314
<% if @minimum_password_length %>
1415
<em>(<%= @minimum_password_length %> characters minimum)</em>
1516
<% end %><br />
16-
<%= f.password_field :password, autocomplete: "new-password" %>
17+
<%= f.password_field :password, class: 'form-control', autocomplete: "new-password" %>
1718
</div>
1819

1920
<div class="field">
2021
<%= f.label :password_confirmation %><br />
21-
<%= f.password_field :password_confirmation, autocomplete: "new-password" %>
22+
<%= f.password_field :password_confirmation, class: 'form-control', autocomplete: "new-password" %>
2223
</div>
2324

2425
<div class="actions">
25-
<%= f.submit "Sign up" %>
26+
<%= f.submit "Sign up", class: 'btn btn-primary' %>
2627
</div>
2728
<% end %>
2829

2930
<%= render "devise/shared/links" %>
31+
32+
</div>
+10-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
1-
<h2>Log in</h2>
1+
<div class="col-md-4 col-md-offset-4">
2+
3+
<img src="http://www.seppo.net/cartoons/albums/cartoons/nature/birds/koskikara_kevat_laulu_eng.jpg" alt="logo">
4+
5+
<h2>Dipper Log in</h2>
26

37
<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>
48
<div class="field">
59
<%= f.label :email %><br />
6-
<%= f.email_field :email, autofocus: true, autocomplete: "email" %>
10+
<%= f.email_field :email, class:'form-control', autofocus: true, autocomplete: "email" %>
711
</div>
812

913
<div class="field">
1014
<%= f.label :password %><br />
11-
<%= f.password_field :password, autocomplete: "current-password" %>
15+
<%= f.password_field :password, class:'form-control', autocomplete: "current-password" %>
1216
</div>
1317

1418
<% if devise_mapping.rememberable? %>
@@ -19,8 +23,10 @@
1923
<% end %>
2024

2125
<div class="actions">
22-
<%= f.submit "Log in" %>
26+
<%= f.submit "Log in", class: 'btn btn-primary' %>
2327
</div>
2428
<% end %>
2529

2630
<%= render "devise/shared/links" %>
31+
32+
</diV>

app/views/layouts/application.html.erb

+8-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
</head>
1111

1212
<body>
13+
<% if user_signed_in? %>
1314
<nav class="navbar navbar-inverse">
1415
<div class="container-fluid">
1516
<!-- Brand and toggle get grouped for better mobile display -->
@@ -27,24 +28,27 @@
2728
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
2829
<ul class="nav navbar-nav">
2930
<li class="active"><a href="/">Home <span class="sr-only">(current)</span></a></li>
30-
<li><a href="#">Project</a></li>
31-
<li><a href="#">Sites</a></li>
31+
<li><%= link_to 'Projects', projects_path%></li>
32+
<li><%= link_to 'Sites', sites_path%></li>
3233
<li class="dropdown">
3334
<a href="#" class="dropdown-toggle"
3435
data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">User <span class="caret"></span></a>
3536
<ul class="dropdown-menu">
36-
<li><a href="#">Profile</a></li>
37+
<li><%= link_to 'Profile', user_path(current_user)%></li>
3738
<li><a href="#">Settings</a></li>
3839
</ul>
3940
</li>
4041
<li><a href="#">Apps Integration(Coming Soon) </a></li>
4142
</ul>
4243
<ul class="nav navbar-nav navbar-right">
43-
<li><a href="#">Log Out</a></li>
44+
<% if user_signed_in? %>
45+
<li><%= link_to('Logout', destroy_user_session_path, method: :delete)%></li>
46+
<% end %>
4447
</ul>
4548
</div><!-- /.navbar-collapse -->
4649
</div><!-- /.container-fluid -->
4750
</nav>
51+
<% end %>
4852
<%= yield %>
4953
</body>
5054
</html>

app/views/projects/_form.html.erb

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<%= form_with(model: project, local: true) do |form| %>
2+
<% if project.errors.any? %>
3+
<div id="error_explanation">
4+
<h2><%= pluralize(project.errors.count, "error") %> prohibited this project from being saved:</h2>
5+
6+
<ul>
7+
<% project.errors.full_messages.each do |message| %>
8+
<li><%= message %></li>
9+
<% end %>
10+
</ul>
11+
</div>
12+
13+
14+
<% end %>
15+
<div class="col-md-4">
16+
<%= form.label(:name, "Name") %>
17+
<%= form.text_field(:name, class: 'form-control') %>
18+
19+
<%= form.label(:description, "Description") %>
20+
<%= form.text_area(:description, class: 'form-control') %>
21+
22+
<%= form.label(:user_id, "User") %>
23+
<%= form.select(:user_id, options_for_select([[current_user.first_name, current_user.id]])) %>
24+
25+
</div>
26+
27+
<div class="actions">
28+
<%= form.submit %>
29+
</div>
30+
<% end %>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
json.extract! project, :id, :created_at, :updated_at
2+
json.url project_url(project, format: :json)

app/views/projects/edit.html.erb

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<h1>Editing Project</h1>
2+
3+
<%= render 'form', project: @project %>
4+
5+
<%= link_to 'Show', @project %> |
6+
<%= link_to 'Back', projects_path %>

0 commit comments

Comments
 (0)