Class: Federails::Client::FollowingsController
- Inherits:
-
Federails::ClientController
- Object
- Federails::ClientController
- Federails::Client::FollowingsController
- Defined in:
- app/controllers/federails/client/followings_controller.rb
Instance Method Summary collapse
-
#accept ⇒ Object
PUT /app/followings/:id/accept PUT /app/followings/:id/accept.json.
-
#create ⇒ Object
POST /app/followings POST /app/followings.json.
-
#destroy ⇒ Object
DELETE /app/followings/1 DELETE /app/followings/1.json.
-
#follow ⇒ Object
POST /app/followings/follow POST /app/followings/follow.json.
-
#new ⇒ Object
GET /app/followings/new?uri=uri.
Instance Method Details
#accept ⇒ Object
PUT /app/followings/:id/accept PUT /app/followings/:id/accept.json
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/federails/client/followings_controller.rb', line 18 def accept respond_to do |format| url = federails.client_actor_url @following.actor if @following.accept! format.html { redirect_to url, notice: I18n.t('controller.followings.accept.success') } format.json { render :show, status: :ok, location: @following } else format.html { redirect_to url, alert: I18n.t('controller.followings.accept.error') } format.json { render json: @following.errors, status: :unprocessable_entity } end end end |
#create ⇒ Object
POST /app/followings POST /app/followings.json
33 34 35 36 37 38 39 |
# File 'app/controllers/federails/client/followings_controller.rb', line 33 def create @following = Following.new(following_params) @following.actor = current_user.federails_actor @following, policy_class: Federails::Client::FollowingPolicy save_and_render end |
#destroy ⇒ Object
DELETE /app/followings/1 DELETE /app/followings/1.json
63 64 65 66 67 68 69 |
# File 'app/controllers/federails/client/followings_controller.rb', line 63 def destroy @following.destroy respond_to do |format| format.html { redirect_to federails.client_actor_url(@following.actor), notice: I18n.t('controller.followings.destroy.success') } format.json { head :no_content } end end |
#follow ⇒ Object
POST /app/followings/follow POST /app/followings/follow.json
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'app/controllers/federails/client/followings_controller.rb', line 43 def follow Federails::Following, policy_class: Federails::Client::FollowingPolicy begin @following = Following.new_from_account following_account_params, actor: current_user.federails_actor rescue ::ActiveRecord::RecordNotFound # Renders a 422 instead of a 404 respond_to do |format| format.html { redirect_to federails.client_actors_url, alert: I18n.t('controller.followings.follow.error') } format.json { render json: { target_actor: ['does not exist'] }, status: :unprocessable_entity } end return end save_and_render end |
#new ⇒ Object
GET /app/followings/new?uri=uri
9 10 11 12 13 14 |
# File 'app/controllers/federails/client/followings_controller.rb', line 9 def new # Find actor (and fetch if necessary) actor = Actor.find_or_create_by_federation_url(params.require(:uri)) # Redirect to local profile page which will have a follow button on it redirect_to federails.client_actor_url(actor) end |