Add follow / unfollow button
This commit is contained in:
parent
44894bf4ff
commit
ce0d3d71fa
3
app/assets/javascripts/relationships.coffee
Normal file
3
app/assets/javascripts/relationships.coffee
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Place all the behaviors and hooks related to the matching controller here.
|
||||||
|
# All this logic will automatically be available in application.js.
|
||||||
|
# You can use CoffeeScript in this file: http://coffeescript.org/
|
||||||
3
app/assets/stylesheets/relationships.sass
Normal file
3
app/assets/stylesheets/relationships.sass
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
// Place all the styles related to the Relationships controller here.
|
||||||
|
// They will automatically be included in application.css.
|
||||||
|
// You can use Sass (SCSS) here: https://sass-lang.com/
|
||||||
15
app/controllers/relationships_controller.rb
Normal file
15
app/controllers/relationships_controller.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
class RelationshipsController < ApplicationController
|
||||||
|
def create
|
||||||
|
profile = Profile.find(params[:followed_id])
|
||||||
|
authorize Relationship
|
||||||
|
current_user.follow(profile)
|
||||||
|
redirect_to profile
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
profile = Relationship.find(params[:id]).followed
|
||||||
|
authorize profile
|
||||||
|
current_user.unfollow(profile)
|
||||||
|
redirect_to profile
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -43,7 +43,10 @@ class TokensController < ApplicationController
|
|||||||
@token.standard = :icrc1
|
@token.standard = :icrc1
|
||||||
@token.transfer_fee = metadata.lines[2].split[7].to_i
|
@token.transfer_fee = metadata.lines[2].split[7].to_i
|
||||||
@token.decimals = metadata.lines[5].split[7].to_i
|
@token.decimals = metadata.lines[5].split[7].to_i
|
||||||
@token.logo_url = metadata.lines[9].split("\"")[1]
|
begin
|
||||||
|
@token.logo_url = metadata.lines[9].split("\"")[1]
|
||||||
|
rescue
|
||||||
|
end
|
||||||
@token.name = metadata.lines[3].split("\"")[3]
|
@token.name = metadata.lines[3].split("\"")[3]
|
||||||
total_supply = `dfx canister --network ic call #{@token.canister_id} icrc1_total_supply 2>&1`
|
total_supply = `dfx canister --network ic call #{@token.canister_id} icrc1_total_supply 2>&1`
|
||||||
@token.total_supply = total_supply.split[0][1..-1].to_i/(10.0**@token.decimals)
|
@token.total_supply = total_supply.split[0][1..-1].to_i/(10.0**@token.decimals)
|
||||||
|
|||||||
2
app/helpers/relationships_helper.rb
Normal file
2
app/helpers/relationships_helper.rb
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
module RelationshipsHelper
|
||||||
|
end
|
||||||
55
app/policies/relationship_policy.rb
Normal file
55
app/policies/relationship_policy.rb
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
class RelationshipPolicy
|
||||||
|
attr_reader :user, :relationship
|
||||||
|
|
||||||
|
def initialize(user, model)
|
||||||
|
@user = user || User.new
|
||||||
|
@relationship = model
|
||||||
|
end
|
||||||
|
|
||||||
|
class Scope
|
||||||
|
def initialize(user, scope)
|
||||||
|
@user = user
|
||||||
|
@scope = scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def resolve
|
||||||
|
if user.admin?
|
||||||
|
scope.all
|
||||||
|
else
|
||||||
|
scope.all
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
attr_reader :user, :scope
|
||||||
|
end
|
||||||
|
|
||||||
|
def index?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def show?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def create?
|
||||||
|
@user.admin? || @user.signed_in?
|
||||||
|
end
|
||||||
|
|
||||||
|
def new?
|
||||||
|
@user.admin? || @user.signed_in?
|
||||||
|
end
|
||||||
|
|
||||||
|
def edit?
|
||||||
|
@user.admin? || @user.id == @relationship.follower_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def update?
|
||||||
|
@user.admin? || @user.id == @relationship.follower_id
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy?
|
||||||
|
@user.admin? || @user.id == @relationship.follower_id
|
||||||
|
end
|
||||||
|
end
|
||||||
3
app/views/profiles/_follow.html.haml
Normal file
3
app/views/profiles/_follow.html.haml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
= form_for(current_user.active_relationships.build) do |f|
|
||||||
|
%div= hidden_field_tag :followed_id, @profile.id
|
||||||
|
= f.submit "Follow"
|
||||||
5
app/views/profiles/_follow_form.html.haml
Normal file
5
app/views/profiles/_follow_form.html.haml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#follow_form
|
||||||
|
- if current_user.following?(@profile)
|
||||||
|
= render 'unfollow'
|
||||||
|
- else
|
||||||
|
= render 'follow'
|
||||||
3
app/views/profiles/_unfollow.html.haml
Normal file
3
app/views/profiles/_unfollow.html.haml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
= form_for(current_user.active_relationships.find_by(followed_id: @profile.id), |
|
||||||
|
html: { method: :delete }) do |f| |
|
||||||
|
= f.submit "Unfollow"
|
||||||
@ -3,6 +3,7 @@
|
|||||||
= @profile.name
|
= @profile.name
|
||||||
- if policy(@profile).edit?
|
- if policy(@profile).edit?
|
||||||
= link_to 'Edit', edit_profile_path(@profile)
|
= link_to 'Edit', edit_profile_path(@profile)
|
||||||
|
= render 'follow_form' if current_user.signed_in?
|
||||||
%p
|
%p
|
||||||
= @profile.summary
|
= @profile.summary
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,10 @@
|
|||||||
Rails.application.routes.draw do
|
Rails.application.routes.draw do
|
||||||
resources :social_links
|
resources :social_links
|
||||||
resources :profiles
|
resources :profiles do
|
||||||
|
member do
|
||||||
|
get :followers
|
||||||
|
end
|
||||||
|
end
|
||||||
resources :tokens do
|
resources :tokens do
|
||||||
member do
|
member do
|
||||||
get 'refresh'
|
get 'refresh'
|
||||||
@ -70,4 +74,5 @@ Rails.application.routes.draw do
|
|||||||
get :following
|
get :following
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
resources :relationships, only: [:create, :destroy]
|
||||||
end
|
end
|
||||||
|
|||||||
15
spec/helpers/relationships_helper_spec.rb
Normal file
15
spec/helpers/relationships_helper_spec.rb
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
# Specs in this file have access to a helper object that includes
|
||||||
|
# the RelationshipsHelper. For example:
|
||||||
|
#
|
||||||
|
# describe RelationshipsHelper do
|
||||||
|
# describe "string concat" do
|
||||||
|
# it "concats two strings with spaces" do
|
||||||
|
# expect(helper.concat_strings("this","that")).to eq("this that")
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
# end
|
||||||
|
RSpec.describe RelationshipsHelper, type: :helper do
|
||||||
|
pending "add some examples to (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
7
spec/requests/relationships_spec.rb
Normal file
7
spec/requests/relationships_spec.rb
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
require 'rails_helper'
|
||||||
|
|
||||||
|
RSpec.describe "Relationships", type: :request do
|
||||||
|
describe "GET /index" do
|
||||||
|
pending "add some examples (or delete) #{__FILE__}"
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user