Я добавляю роль моего последователя.но это происходит с приведенной ниже ошибкой, касающейся моего метода Follow, когда я нажимаю на кнопку Follow, которая находится на странице показа пользователей.Я не уверен, что это значит или как решить.Я смотрел на другие вопросы и читал документы, но не повезло.Я даже не уверен на 100%, если мой метод правильный.спасибо.
class User < ApplicationRecord
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable, :trackable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :validatable
has_many :tweets
mount_uploader :photo, PhotoUploader
validates :photo, presence: :true
acts_as_followable
acts_as_follower
end
Started POST "/users/3/follow" for 127.0.0.1 at 2018-10-22 18:58:33 +0100
Processing by UsersController#follow as HTML
Parameters: {"authenticity_token"=>"qsRjm2CxBJ5jy8zAyL8m6hJAvOS4kZuQwwsLLcD2NmbgCs+uDsOoOtceQKJ69CXMVskIOSPAk0/R6t1yroOM7g==", "id"=>"3"}
User Load (2.0ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 ORDER BY "users"."id" ASC LIMIT $2 [["id", 7], ["LIMIT", 1]]
↳ /Users/benherring/.rbenv/versions/2.4.4/lib/ruby/gems/2.4.0/gems/activerecord-5.2.1/lib/active_record/log_subscriber.rb:98
User Load (0.7ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 3], ["LIMIT", 1]]
↳ app/controllers/users_controller.rb:12
Follow Load (0.8ms) SELECT "follows".* FROM "follows" WHERE "follows"."follower_id" = $1 AND "follows"."follower_type" = $2 AND "follows"."followable_id" = $3 AND "follows"."followable_type" = $4 LIMIT $5 [["follower_id", 7], ["follower_type", "User"], ["followable_id", 3], ["followable_type", "ApplicationRecord"], ["LIMIT", 1]]
↳ app/controllers/users_controller.rb:13
(0.3ms) BEGIN
↳ app/controllers/users_controller.rb:13
(0.2ms) ROLLBACK
↳ app/controllers/users_controller.rb:13
Completed 500 Internal Server Error in 16ms (ActiveRecord: 4.0ms)
TypeError (no implicit conversion of nil into String):
app/controllers/users_controller.rb:13:in `follow'
class UsersController < ApplicationController
def show
@user = User.find(params[:id])
@tweets = @user.tweets.order('created_at DESC')
authorize @user
end
def follow
@user = User.find(params[:id])
current_user.follow(@user)
authorize @user
@follow = Follow.find_by(follower: @current_user, followable: @user)
end
def unfollow
@user = User.find(params[:id])
current_user.stop_following(@user)
end
end
<% if current_user.following?(@user) %>
<%= button_to "Following", {action: "unfollow", id: @user.id}, method: "post", class: "btn btn-secondary btn_unfollow"%>
<% else %>
<%= button_to "Follow", {action: "follow", id: @user.id}, method: "post", class: "btn btn-primary btn_follow" %>
<% end %>
] 2 ] 2