[RUBY] I want to set the conditions to be displayed in collection_check_boxes

This is the first post of a beginner. I will post it in a memo so that I will not forget it.

form_with helper method I'm trying to create a checkbox using collection_check_boxes.

・ What you want to implement Only the name of the customer registered by the logged-in user I want to display it as a check box (current_user.id == user.id I want to make the name of the customer table of the check box. )

Normal description method Here, the names of all customer tables become checkboxes.

 = f.collection_check_boxes :customer_ids, Customer.all, :id, :name

solution ↓ I was able to solve it here.

 = f.collection_check_boxes :customer_ids, Customer.where(user_id: current_user.id), :id, :name

It's a simple content, I couldn't find an article with the same content pinpointed, so I posted it.

I would appreciate it if you could comment if there are any mistakes in the description.

Recommended Posts

I want to set the conditions to be displayed in collection_check_boxes
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
I want to be eventually even in kotlin
I want to get the value in Ruby
I want to embed any TraceId in the log
I want to be aware of the contents of variables!
How to set the log level to be displayed in the release version of orhanobut / logger
[Android Studio] I want to set restrictions on the values registered in EditText [Java]
I want to transition to the same screen in the saved state
I want to simplify the conditional if-else statement in Java
I want to display the images under assets/images in the production environment
I want to remove the top margin in Grouped UITableView (swift)
[Java] I want to perform distinct with the key in the object
I want to change the value of Attribute in Selenium of Ruby
[Android] I want to get the listener from the button in ListView
I want to use @Autowired in Servlet
[Ruby] I want to output only the odd-numbered characters in the character string
I want to get the IP address when connecting to Wi-Fi in Java
I want to display an error message when registering in the database
I want to output the day of the week
I want to send an email in Java.
I tried to organize the session in Rails
I want to use arrow notation in Ruby
I want to var_dump the contents of the intent
I want to pass APP_HOME to logback in Gradle
rsync4j --I want to touch rsync in Java.
[Xcode] I want to manage images in folders
I tried to set tomcat to run the Servlet.
I want to truncate after the decimal point
I was addicted to the NoSuchMethodError in Cloud Endpoints
I want to use Combine in UIKit as well.
How to set the display time to Japan time in Rails
I tried to organize the cases used in programming
I want to do something like "cls" in Java
[Java] I want to calculate the difference from the date
Tokoro I rewrote in the migration from Wicket 7 to 8
I want to use fish shell in Laradock too! !!
I want to use ES2015 in Java too! → (´ ・ ω ・ `)
I want to judge the range using the monthly degree
I want to use a little icon in Rails
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 dark mode with the SWT app
I want to define a function in Rails Console
I want to stop snake case in table definition
I want to call the main method using reflection
If you want to recreate the instance in cloud9
I want to click a GoogleMap pin in RSpec
[Rough commentary] I want to marry the pluck method
I tried to implement the Euclidean algorithm in Java
I want to return the scroll position of UITableView!
I want to simplify the log output on Android
I want to add a delete function to the comment function
Rspec: I want to test the post-execution state when I set a method on subject
I want to change the path after new registration after logging in with multiple devises.
I want to morphologically analyze the log in the DB and put it in the DB to classify messages 1
I want to place RadioButtons in the same RadioGroup at any position on the screen.
[Rails] I want to display the link destination of link_to in a separate tab
# 1_JAVA I want to get the index number by specifying one character in the character string.
I want to hit the API with Rails on multiple docker-composes set up locally
[Beginner] I want to modify the migration file-How to use rollback-