[RUBY] [Refactoring] How to write routing

Overview

A neat way to write routing: relaxed:

background When specifying the routing, if you use 6 out of 7 actions, if you write it as only, it will be messy and long, and I personally became crap: weary: so I will leave it as a memorandum: bow_tone1:

Rails 7 Actions

First, let's review the seven Rails actions: writing_hand:

Action role
index Display a list
new to add
create Register additional content
edit To edit
update Update your edits
destroy delete
show Display individual contents

How to write

: warning: Here we route to a resource called "tweets"

When implementing all 7 actions

routes.rb



  resources :tweets

To limit the actions used

: warning: Here, "index", "new", and "create" are used.

routes.rb



  resources :tweets, only: [:index, :new, :create]

When deleting unnecessary actions

: warning: Here, we will use an action other than "show".

routes.rb



  resources :tweets, except: [:show]

Summary

It's easy to fill in ** only **, but using ** except ** makes the code cleaner and easier to read: point_up: I will also keep in mind: sparkles: laughing:

reference

https://web-camp.io/magazine/archives/16815

Recommended Posts

[Refactoring] How to write routing
How to write Rails routing
How to write Rails
How to write dockerfile
How to write docker-compose
How to write Mockito
How to write migrationfile
How to write good code
Bit Tetris (how to write)
How to write java comments
Great poor (how to write)
[Note] How to write Dockerfile/docker-compose.yml
How to write Junit 5 organized
How to write Rails validation
How to write Rails seed
[Ruby] How to write blocks
Studying Java # 6 (How to write blocks)
[Rails] How to write in Japanese
Baseball ball count (how to write)
How to write a ternary operator
Rails on Tiles (how to write)
[Rails] How to write exception handling?
How to write Java variable declaration
Y-shaped road tour (how to write)
How to write easy-to-understand code [Summary 3]
[RSpec] How to write test code
[Basic] How to write a Dockerfile Self-learning ②
[Introduction to Java] How to write a Java program
How to deploy
[Java] How to output and write files!
[rails] How to configure routing in resources
How to write Spring AOP pointcut specifier
How to write an RSpec controller test
[SpringBoot] How to write a controller test
How to write and explain Dockerfile, docker-compose
JDBC promises and examples of how to write
Rails: How to write a rake task nicely
[JavaFX] How to write Eclipse permissions in build.gradle
How to write offline 15th reference question answer
[Rails] How to write when making a subquery
Java Development Basics ~ How to Write Programs * Exercise 1 ~
How to write an if statement to improve readability-java
JUnit 5: How to write test cases in enum
Offline real-time how to write F06 implementation example
How to write code that thinks object-oriented Ruby
How to write test code with Basic authentication
How to write React Native bridge ~ Android version ~
[Java] Memo on how to write the source
How to write Java String # getBytes in Kotlin?
Notes on how to write comments in English
How to call AmazonSQSAsync
How to use Map
How to use rbenv
How to use letter_opener_web
How to use with_option
How to use fields_for
How to use java.util.logging
How to use map
How to use collection_select
How to adapt Bootstrap
How to use Twitter4J