Home>
I have a question about the method of the follow function of the rails tutorial.
Why should follow (other_user) following<
Do you not understand it properly, or is it not good either? I will think.
#Follow users
def follow (other_user)
following<<other_user
end
#Unfollow user
def unfollow (other_user)
active_relationships.find_by (followed_id: other_user.id) .destroy
end
# Returns true if the current user is following
def following? (other_user)
following.include? (other_user)
end
has_many: active_relationships, class_name: "Relationship",
foreign_key: "follower_id",
dependent:: destroy
has_many: following, through:: active_relationships, source:: followed
-
Answer # 1
Related articles
- ruby on rails - rails tutorial chapter 13 cooperation between heroku and aws s3 region
- ruby on rails - in the rails tutorial (4th edition, chapter 5), the layout of only the login page is broken
- ruby - i got stuck in chapter 5 of the rails tutorial i want to apply it because applicationhtmlerb is not applied
- ruby on rails 6 - rails tutorial (6th edition, chapter 8, list 833) what is the difference between logged_in? and is_logged_in ?
- ruby - about rails routing
- ruby - [rails] about the error that occurs when deleting likes (routing error)
- ruby on rails - [rails] about the problem that screen transition is not possible (error does not occur)
- ruby on rails - about the matter that does not transition to the detail page
- ruby - about embedding rails videos
- ruby on rails - about saving comments
- ruby on rails - about deploying apps using s3 function
- ruby on rails - about the description in applicationjs
- ruby - about routing using rails collection
- ruby on rails - about nomethoderror in skilscontroller # create
- ruby on rails - about multi-word search to multiple columns using ransack
- ruby on rails - rails tutorial tests that should pass fail with an error [6th edition]
- ruby on rails - about image distribution on heroku and s3
- ruby on rails - about conditional branching using elsif
- ruby on rails - about rails composite indexes
Trends
- python - you may need to restart the kernel to use updated packages error
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- javascript - how to check if an element exists in puppeteer
- dart - flutter: the instance member'stars' can't be accessed in an initializer error
- sh - 'apt-get' is not recognized as an internal or external command, operable program or batch file
- i want to call a child component method from a parent in vuejs
- python 3x - typeerror: 'method' object is not subscriptable
This does not hold.
active_relationships
The element ofRelationship
AndUser
Is not.If you want to delete the entire user, the latter is fine, but that's not what you want to do, right?