Add post feed

This commit is contained in:
TheNeedful-DO 2023-11-15 13:05:07 +00:00
parent ad43bd2064
commit 89eb06febb
8 changed files with 33 additions and 3 deletions

View File

@ -1,4 +1,5 @@
class MicropostsController < ApplicationController
before_action :set_micropost, only: %i[ show edit update destroy ]
def create
@micropost = current_user.microposts.build(micropost_params)
authorize @micropost
@ -11,9 +12,19 @@ class MicropostsController < ApplicationController
end
def destroy
authorize @micropost
@micropost.destroy
respond_to do |format|
format.html { redirect_to request.referrer || root_url, notice: "Post was deleted." }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_micropost
@micropost = Micropost.find(params[:id])
end
def micropost_params
params.require(:micropost).permit(:content)

View File

@ -4,5 +4,6 @@ class VisitorsController < ApplicationController
def index
@doodads = authorize policy_scope(Doodad)
@canisters = authorize Canister.all
@feed_items = current_user.feed.paginate(page: params[:page])
end
end

View File

@ -121,4 +121,8 @@ class User < ActiveRecord::Base
following.include?(leader)
end
def feed
Micropost.where("user_id = ?", id)
end
end

View File

@ -30,7 +30,7 @@ class UserPolicy
end
def show?
@current_user.admin? || @current_user == @user
@current_user.admin? || @current_user == @user || true
end
def home?

View File

@ -2,3 +2,5 @@
%span= link_to micropost.user.display_name, micropost.user
%span.content= micropost.content
%span.timestamp Posted #{time_ago_in_words(micropost.created_at)} ago.
- if policy(micropost).destroy?
%span= link_to "❌", micropost, method: :delete, data: { confirm: 'Are you sure?' }

View File

@ -0,0 +1,6 @@
- if @feed_items.any?
%ol.microposts
= render @feed_items
= will_paginate @feed_items
- else
%span No items in feed.

View File

@ -1,5 +1,6 @@
%section.micropost_form
= render 'shared/micropost_form'
- if current_user.signed_in?
%section.micropost_form
= render 'shared/micropost_form'
.contain
%h1 #{@user.display_name if @user.display_name}

View File

@ -4,8 +4,13 @@
- else
%h1 Web3 Social Gaming <br/>Crypto Rewards
- if @feed_items.any?
.contain
%h2 Post feed
= render 'shared/feed'
.contain
#doodads
%h2 Doodads
- if current_user.signed_in?
%p= link_to '+ New Doodad', new_doodad_path
= render @doodads