[RUBY] Rails basics

current_user method

A method that can be used when the login function is implemented in devise. A record with id 1 has the same meaning as User.find (1). You can get the value with current_user.name etc.

To display different pages for each user in routing, use an unusual description method.


get 'users/:id' => 'users#show'

where method One of Active Record You can get an instance of a record that matches the condition taken as an argument in model.where (condition) as an array type. If you describe the conditions consecutively, you can get records that meet multiple conditions.

Sample.where('id < 3').where('user_id: 1')


Defining relationships between models makes it easy to call data across models.

Recommended Posts

Rails basics
Rails Routing Basics
Rails database basics
Rails Logger Basics
Rspec Basics [Rails]
Ruby on Rails basics
[Rails] Introduction of devise Basics
[Rails g.error]
Rails Review 1
Rails API
Rails migration
Ruby basics
Ruby basics
[Rails] first_or_initialize
rails tutorial
Fragment basics
JPA Basics 1
About Rails 6
Docker basics
ViewPager basics
Rails foundation
Rails memorandum
rails tutorial
Java basics
rails tutorial
rails tutorial
Java basics
RSpec Basics
JavaScript basics
[Rails] devise
rails tutorial
JPA Basics 2
rails tutorial
Hash basics
Java basics
Rails Tips
rails method
rails tutorial
Ruby basics
[Rails] ActiveRecord
[Rails] form_with
RecyclerView Basics
Rails Review 2
Rails Basics of creating a new application
Rails6 jQuery introduced
About Rails routing
Add binding.pry (rails)
Rails access restrictions
Rails and FormData
rails tutorial Chapter 6
Rails tutorial test
Rails render redirect_to
[Rails] Favorite feature
Rails Bootstrap introduced
[Rails] Many-to-many creation
[Rails] Naming convention
Rails Credentials Note
java programming basics
[Rails] Introducing jquery
[Rails 6] Ranking function
Rails Flash Message