Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating likes #2

Merged
merged 5 commits into from
Nov 25, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Trying to get button to work
Beckyrose200 committed Nov 25, 2021

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit eb4341a591150d39199f8311cdc851888c5ca3a2
Empty file.
9 changes: 6 additions & 3 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
@@ -12,9 +12,12 @@ def index
@posts = Post.all
end

# def update
# redirect_to posts_url
# end
def update(id)
post = Post.find_by(id: id)
post.update(likes: (post.likes + 1 ))
redirect_to posts_url
end


private

87 changes: 79 additions & 8 deletions app/views/posts/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,83 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

</head>
<body>

<nav class="navbar navbar-dark bg-primary">
<div class="container-fluid">
<a class="navbar-brand">Acebook</a>
<form class="d-flex">
<input class="form-control me-2" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
</div>
</nav>

<ul class="nav justify-content-end">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Profile</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Settings</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">Sign Out</a>
</li>
</ul>

<p1 class="h2 offset-1"> <%= link_to new_post_path do %>
Write a post
<% end %> </p1>

<div class="center"
<div class="mb-3 offset-4" style="text-align: center;">
<label for="post" class="form-label"> <h4>Whats on your mind?</h4></label>
<textarea class="form-control offset-4" id="exampleFormControlTextarea1" rows="4" style="width: 40rem;"></textarea>
<div class="row">
<br>
</div>
</div>
</div>

<% @posts.each do |post| %>
<p><%= post.message %></p>
<div class="container">
<div class ="row offset-4">
<div class="card" style="width: 30rem;">
<div class="card-body">
<h5 class="card-title">Users name</h5>
<h6 class="card-subtitle mb-2 text-muted">26/11/2021</h6>
<p class="card-text"><%= post.message %></p>


<button id = '<%= post.message %>' value='<%=post.message%>'><%= post.likes %> Likes </button>
<p><%=post.likes%></p>
<% end %>
<% end %>


<%= link_to new_post_path do %>
New post

<button_to 'Add Like', update_path(post.id) id = '<%= post.message %>'><%= post.likes %> Likes </button>
<%= button_to 'Press me', update_path(post.id), method: :get %>
<a href="#" class="card-link">Comment</a>


</div>
</div>
<div class="row">
<br>
</div>
</div>
</div>
<% end %>


</body>
</html>
</div>

15 changes: 14 additions & 1 deletion app/views/posts/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">

</head>
<body>


<%= form_for @post do |form| %>
<%= form.label :message %>
<%= form.text_field :message %>

<%= form.submit "Submit" %>
<% end %>