Skip to content

Commit d9f8dac

Browse files
committed
Created Projects and its functionality
1 parent a189af0 commit d9f8dac

21 files changed

Lines changed: 179 additions & 9 deletions

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Place all the behaviors and hooks related to the matching controller here.
2+
# All this logic will automatically be available in application.js.
3+
# You can use CoffeeScript in this file: http://coffeescript.org/
Binary file not shown.

app/assets/stylesheets/application.css.scss

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,18 @@ input[type="submit"], .button {
174174
}
175175
}
176176

177+
.project_button {
178+
background: $highlight;
179+
color: $white;
180+
text-decoration: none;
181+
padding: 1em 2em;
182+
}
183+
184+
.button_wrapper{
185+
margin: 4em 0 0 0;
186+
text-align: center;
187+
}
188+
177189

178190
@import 'welcome';
179191
@import 'posts_projects';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Place all the styles related to the projects controller here.
2+
// They will automatically be included in application.css.
3+
// You can use Sass (SCSS) here: http://sass-lang.com/
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class ProjectsController < ApplicationController
2+
before_action :find_project, only: [:show, :edit, :update, :destroy]
3+
def index
4+
@projects = Project.all.order("created_at desc")
5+
end
6+
7+
def new
8+
@project = Project.new
9+
end
10+
11+
def create
12+
@project = Project.new project_params
13+
14+
if @project.save
15+
redirect_to @project, notice: "Nice Mohit! Project was successfully saved!!!"
16+
else
17+
render 'new', notice: "Oops! Project couldn't be saved!!!"
18+
end
19+
end
20+
21+
def show
22+
23+
end
24+
25+
private
26+
27+
def find_project
28+
@project = Project.find(params[:id])
29+
end
30+
31+
def project_params
32+
params.require(:project).permit(:title, :description, :link)
33+
end
34+
end

app/controllers/welcome_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ class WelcomeController < ApplicationController
22

33
def index
44
@posts = Post.all.limit(3).order("created_at desc")
5+
@projects = Project.all.limit(3).order("created_at desc")
56
end
67
end

app/helpers/projects_helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module ProjectsHelper
2+
end

app/models/project.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
class Project < ActiveRecord::Base
2+
end

app/views/layouts/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
<%= link_to "Mohit Chandana", root_path, class: "name" %>
1616
<nav>
1717
<%= link_to "Articles", posts_path %>
18+
<%= link_to "Projects", projects_path %>
1819
<a href="#">Projects</a>
1920
<a href="#">Contact</a>
2021
</nav>

app/views/posts/_form.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<% if @post.errors.any? %>
33
<h2><%= pluraize(@post.errors.count, "error") %> prevented this post from saving:</h2>
44
<ul>
5-
<% @posts.errors.full_messages.each do |msg| %>
5+
<% @post.errors.full_messages.each do |msg| %>
66
<li><%= msg %></li>
77
<% end %>
88
</ul>

0 commit comments

Comments
 (0)