Recently, the "world's worst login code" has become a hot topic, but it is not a security issue to place data in Rails and use for or each in the view. What?
Now, we have created the Users table and the Musics table that stores the songs associated with each user, and the process of retrieving them in the view is written as follows. (In Haml)
[email protected] musics.each do | music | -user = User.find_by (id: musics.user_id) % tr % td = music.user_id % td = user.username % td = music.title
On the controller side, only the process of putting Musics.all into @musics.
Is it better to perform all processing on the controller side except for displaying data?
If it is processed on the controller side, I can not think of a method, but what kind of method is there ...
Please teach me. .
Answer # 1
If you declare
Music, you can get users linked by
If it is left as it is,
musicwill be subtracted by
@musics = Music.include (: user) .where .. Let's pull it together like..
Active Record Association (Association)-Rails Guide
- ruby on rails - the capacity shortage of cloud 9 and ec2 cannot be solved
- ruby - the formhelper module set by rails is not loaded
- [ruby on rails] i want to use pluck method to display the values separated by "," in the form field
- ruby on rails - unable to autoload constant cannot be solved
- ruby - [rails] error when trying to create order model from product_controller
- ruby - rails tutorial please let me ask about email resetting
- ruby on rails ruby calculation method description method
- ruby on rails 5 - rails association about one-to-many association
- ruby on rails 5 - argumenterror on scope
- ruby on rails: gem install sqlite3 command does not pass
- how to connect minimagick and imagemagick of ruby on rails on windows
- ruby - rails nomethoderror cannot be resolved
- ruby - rails server can't start
- ruby - i want to start a rails server
- ruby on rails - why is the root directory in scss path specification not "~/"?
- ruby - [rails] resolve nameerror in items#new and want to be able to save image data
- ruby on rails - in rails command, undefined method `application' for rails:module (nomethoderror) comes out
- ruby on rails - rils i don't want to make transitions by hand (you will be redirected before entering the edit screen)
- ruby on rails - about joining/extracting rails 6 tables
- ruby on rails - bitbucket push doesn't work (rails tutorial)
- ruby - when editing the initial value of text_field
- ruby - i don't know how to put data scraped by nokogiri into sqlite3 database
- ruby - i want to display the chart of chartkick in index for each record of the table
- ruby - how to pass data from rails 6 model to vuejs
- ruby - [rails] i want to get the latest multiple data from the database
- ruby - rails db:create cannot be done rails + postgresql environment construction
- ruby - i get an argumenterror
- you can do redirect_to with ruby on rails, but you get nomethoderror when rendering