Add post feed
This commit is contained in:
parent
ff3de26b48
commit
a6f084a372
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -121,4 +121,8 @@ class User < ActiveRecord::Base
|
||||
following.include?(leader)
|
||||
end
|
||||
|
||||
def feed
|
||||
Micropost.where("user_id = ?", id)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@ -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?
|
||||
|
||||
@ -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?' }
|
||||
|
||||
6
app/views/shared/_feed.html.haml
Normal file
6
app/views/shared/_feed.html.haml
Normal file
@ -0,0 +1,6 @@
|
||||
- if @feed_items.any?
|
||||
%ol.microposts
|
||||
= render @feed_items
|
||||
= will_paginate @feed_items
|
||||
- else
|
||||
%span No items in feed.
|
||||
@ -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}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user