[RUBY] [Controller] I want to retrieve the numerical value of a specific column from the DB (my memo)

Table A: user B table: user_info

Purpose: I want to return the numerical value of a specific column (user_main_id in this case) of table B

manner: Only @user_session of A table is prepared.

  1. Find the id in @user_session in the A table.
  2. Match the id of table A with the number of user_id of table B
  3. Get the target column (user_main_id) after matching by id in B table


API display name: user.find_by(user_id: @user_session.record.id).user_main_id 

What is important about the contents of @user_session!

Reference URL https://qiita.com/tsuchinoko_run/items/f3926caaec461cfa1ca3

Recommended Posts

[Controller] I want to retrieve the numerical value of a specific column from the DB (my memo)
I want to make a specific model of ActiveRecord ReadOnly
I want to change the value of Attribute in Selenium of Ruby
A memo when you want to clear the time part of the calendar
How to return a value from Model to Controller using the [Swift5] protocol
[Ruby] I want to extract only the value of the hash and only the key
I want to output the day of the week
Set the time of LocalDateTime to a specific time
I want to var_dump the contents of the intent
I want to get the value in Ruby
I want to get the value of Cell transparently regardless of CellType (Apache POI)
I want to recursively get the superclass and interface of a certain class
I want to get a list of only unique character strings by excluding fixed character strings from the file name
[Ruby] I want to make a program that displays today's day of the week!
I want to go back to a specific VC by tapping the back button on the NavigationBar!
I want to call a method of another class
[Java] I want to calculate the difference from the date
A memo of what I did from a blank state to searching for characters using the "grep command" on "Ubuntu"
I want to know the answer of the rock-paper-scissors app
I want to display the name of the poster of the comment
I want to monitor a specific file with WatchService
[Rails] I want to display the link destination of link_to in a separate tab
Extract a specific element from the list of objects
I want to add a reference type column later
I want to reduce the number of unnecessary queries. From considering counter_cache to introducing counter_culture.
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to connect to Heroku MySQL from a client
I want to add a delete function to the comment function
I want to fetch another association of the parent model from the intermediate table with has_many
I want to get a list of the contents of a zip file and its uncompressed size
I want to return a type different from the input element with Java8 StreamAPI reduce ()
I want to recreate the contents of assets from scratch in the environment built with capistrano
I want to expand the clickable part of the link_to method
I want to change the log output settings of UtilLoggingJdbcLogger
I want to call a method and count the number
I want to create a form to select the [Rails] category
[Ruby] How to retrieve the contents of a double hash
I want to put the JDK on my Mac PC
I want to give a class name to the select attribute
I want to narrow down the display of docker ps
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
[Spring Boot] I want to add my own property file and get the value with env.getProperty ().
When you want to check whether the contents of a property can be converted to a specific type
I want to know the Method of the Controller where the Exception was thrown in the ExceptionHandler of Spring Boot
I want to recursively search for files under a specific directory
I want to understand the flow of Spring processing request parameters
The story of Collectors.groupingBy that I want to keep for posterity
I made a gem to post the text of org-mode to qiita
I want to limit the input by narrowing the range of numbers
I want to control the default error message of Spring Boot
I made a tool to output the difference of CSV file
[Android] I want to get the listener from the button in ListView
I want to import the pull-down menu items when submitting a form in Rails into CSV and display them from the DB data.
I want to graph the number of photo AC downloads [MySQL ring cooperation] ~ Coding 10 lines a day ~
I tried to make a parent class of a value object in Ruby
A memo that was soberly addicted to the request of multipart / form-data
[Rails] I learned about migration files! (Adding a column to the table)
[Rails] I want to send data of different models in a form
I want to display the number of orders for today using datetime.