A community-driven Ruby on Rails style guide

23 Sep.,2024

 

A community-driven Ruby on Rails style guide

# db/migrate/<migration_file_name>.rb

For more information, please visit Yongyang.

# frozen_string_literal: true

# bad

class

ModifyDefaultStatusForProducts

<

ActiveRecord

::

Migration

def

change

old_status

=

'pending_manual_approval'

new_status

=

'pending_approval'

reversible

do

|

dir

|

dir

.

up

do

Product

.

where

(

status

:

old_status

)

.

update_all

(

status

:

new_status

)

change_column

:products

,

:status

,

:string

,

default

:

new_status

end

dir

.

down

do

Product

.

where

(

status

:

new_status

)

.

update_all

(

status

:

old_status

)

change_column

:products

,

:status

,

:string

,

default

:

old_status

end

end

end

end

# good

# Define `table_name` in a custom named class to make sure that you run on the

# same table you had during the creation of the migration.

# In future if you override the `Product` class and change the `table_name`,

# it won't break the migration or cause serious data corruption.

class

MigrationProduct

<

ActiveRecord

::

Base

self

.

table_name

=

:products

end

class

ModifyDefaultStatusForProducts

<

ActiveRecord

::

Migration

def

change

old_status

=

'pending_manual_approval'

new_status

=

'pending_approval'

reversible

do

|

dir

|

dir

.

up

do

MigrationProduct

.

where

(

status

:

old_status

)

.

update_all

(

status

:

new_status

)

change_column

:products

,

:status

,

:string

,

default

:

new_status

end

dir

.

down

For more Japanese Standard Railsinformation, please contact us. We will provide professional answers.

do

MigrationProduct

.

where

(

status

:

new_status

)

.

update_all

(

status

:

old_status

)

change_column

:products

,

:status

,

:string

,

default

:

old_status

end

end

end

end

Which Japan Rail Pass To Choose for Your Trip

A Japan Rail Pass (JR Pass) gives you unlimited travel on bullet trains (Shinkansen) and regular Japan Rail trains. It can save you lots of time &#; and some money. There are a few different options, and which one you ultimately choose depends on how long you&#;re traveling and the level of comfort you want.

There are also various regional rail passes. So if your travel plan are limited to a particular region you should also consider those. Whatever your travel plans are, we&#;ve got you covered with everything you know to pick the right pass for your trip.

Jump to:

Quick summary: If you want to keep it simple, order the Japan Rail (JR) Pass online before your trip.

Is the JR Pass worth it? If you&#;re traveling to four or five major cities within seven days, it&#;s likely you&#;ll be saving money. For example, from Tokyo travel to Kyoto, Osaka, Hiroshima, Kanazawa and back.

One of the easiest and cheapest options for ordering the JR Pass is Klook. Shipping is free.

It&#;s also worth checking on KKday and on Headout.

The Japan Rail Pass: Everything you need to know

The Japan Rail Pass is the mother of all travel passes, allowing you unlimited rides on all JR trains from Kagoshima at the bottom end of Kyūshū right up to the northern tip of Hokkaidō. You can ride everything from the super-cool Shinkansen (that&#;s the bullet train) to local, rapid, and limited express JR trains; select JR buses; and even a ferry.

It&#;s the (nearly) unlimited access to the Shinkansen that gives the pass its true value. Japan&#;s Shinkansen network is comprehensive and growing! Read up on everything Shinkansen here.

Note: JR Pass holders are now able to ride on all types of Shinkansen, including the Nozomi and Mizuho services if they buy a special extra ticket.

What does the JR Pass cover?

  • All JR trains.
  • Local JR buses routes, but NOT intercity JR bus routes. Local JR bus routes often connect a major JR train station with area attractions, like hot spring resorts and trailheads. However, not all local buses are run by JR. Even with a JR Pass, you might find yourself having to pay extra to ride a local bus to reach your final destination.
  • The JR Miyajima Ferry between the pier at JR Miyajimaguchi Station and the pier on Miyajima, a popular attraction.
  • Select non-JR lines, including: the Tokyo Monorail (from Haneda Airport); the Aomori Railway between Aomori and Hachinohe in Tōhoku (but only if disembarking at Aomori, Noheji, or Hachinohe stations); the IR Ishikawa Railway between Kanazawa and Tsubata (provided you do not disembark mid-way); the Ainokaze Toyama Railway between Toyama and Takaoka (provided you do not disembark mid-way).

What is NOT covered by the JR Pass?

All non-JR lines save for the few mentioned above. This becomes a little tricky when there are sections of private railway interrupting stretches of JR tracks. For example, getting from Tokyo to Mount Fuji by train requires travel along a length of tracks owned by Fujikyū Railway; as a result, pass holders must pay a small surcharge to cover passage through this section of tracks.

Nikkō and Shimoda (at the southern tip of the Izu Peninsula) are two other popular destinations where special rules and/or additional costs apply. See our guide to getting from Tokyo to Nikkō for advice on how to do this journey on a JR Pass without paying extra.

Who can purchase a JR Pass?

The All Japan Rail Pass can only be used by travelers entering Japan on a foreign passport with a &#;temporary visitor&#; visa (aka a tourist visa). Japanese nationals as well as foreign residents on any other kind of visa cannot buy one.

Not eligible? A handful of regional rail passes are available to long-term foreign residents of Japan (meaning you have a foreign passport but some other kind of visa, like a work visa). Another options is to get a Japan Bus Pass &#; these can be used by anyone with a foreign passport!

How much does the JR Pass cost?

The cost of the pass depends on the duration of the pass, the class, and how you buy it. It is cheapest to buy the pass overseas; the prices quoted below are the prices for purchasing overseas.

Validity period Standard Green Car (Business Class) Booking link 7 days

¥

50,000

¥

70,000

Order via Klook or Headout 14 days

¥

80,000

¥

110,000

Order via Klook or Headout 21 days

¥

100,000

¥

140,000

Order via Klook or Headout

*Prices were accurate as of July 1, .

The JR Pass is also available at KKday.

Important: The duration of each JR pass is the number of days from when it is first activated &#; including that day. The passes are valid for travel on consecutive days only. There is no option to split up travel &#; so once you activate your JR Pass, the clock starts. Choose carefully, because you won&#;t be able to change the pass &#; either the duration or the class &#; after you arrive.

Is there a JR Pass for children?

Yes, children aged 6&#;11 are eligible for a half-priced rail pass. Children must be no older than 11 on the day the pass is purchased.

JR Pass prices for children 6&#;11:

Validity period Standard Green Car (Business Class) Booking link 7 days

¥

25,000

¥

35,000

Order via Klook or Headout 14 days

¥

40,000

¥

55,000

Order via Klook or Headout 21 days

¥

50,000

¥

70,000

Order via Klook or Headout

*Prices were accurate as of July 1, .

The JR Pass is also available at KKday.

Children five and under ride for free on Japanese trains; however, they are not guaranteed a seat. Only pass holders can reserve seats, so if you want to guarantee a seat for your child/children under six, they will need their own (children&#;s) pass. Otherwise, they can sit in any unclaimed seats. If there aren&#;t any left, the child must ride on your lap.

For this reason, only one child under six per adult is allowed to ride for free on the Shinkansen. To ride for free, children should be under six on the day of travel (in case passports are checked).

Is a Green Car pass worth it?

JR&#;s &#;Green Car&#; is equivalent to business class. All Shinkansen lines and some commuter lines have Green Cars. Some newer model Shinkansen also have &#;Gran Class&#; cars, which would be equivalent to first class. There is no Gran Class JR Pass.

An upgrade gives you more space: Ordinary Shinkansen cars seat three on one side of the aisle and two on the other, whereas Green Cars seat two and two across the aisle. The seats and armrests are a little bigger, and each seat has its own power point for charging. There&#;s also more legroom, more space for reclining, and a foot rest.

For reasons not related to actual JR policy, the Green Car is usually quieter than the regular cars.

The big downside is that there are no unreserved seat Green Cars, which means you must have a reserved seat for every leg of your journey. This does not cost extra, but it means that you can&#;t just show up at the station and jump on whatever train pulls into the platform next.

Also most trains may have only one &#; or at most up to three &#; Green Cars, so there are just less seats in general to reserve. (Though of course reservations for ordinary cars tend to fill up faster anyway).

Services that MAY have no Green Cars include: Most Hikari and Kodama services on the Sanyō Shinkansen (Shin-Osaka to Hakata); some Sakura and Tsubame services on the Kyūshū Shinkansen (Hakata to Kagoshima); and all Kamome services on the Nishi Kyūshū Shinkansen.

Pro tip: Many of the bullet trains have power outlets available in front of or next to your seat, so that you can charge your and use your laptop; it just depends on whether the line you&#;re riding runs newer or older series trains. You can also connect to free Wi-Fi on an increasing number of Shinkansen, though connection can by spotty (think: frequent tunnels). Read more about getting Wi-Fi in Japan.

Deciding between a 7-, 14-, or 21-day pass

We envy anyone who even gets to consider a 21-day pass! Most travelers find themselves deciding between the 7-day and the 14-day pass. What you ultimately choose obviously depends on where you plan to go and how long you plan to be in Japan.

Cost breakdown per day by pass

Validity period Standard Green Car 7-day pass

¥

7,143

¥

10,000

14-day pass

¥

5,714

¥

7,857

21-day pass

¥

4,761

¥

6,666

*Prices were accurate as of July 1, .

The easiest way to stretch a 7-day JR Pass on a longer trip is to spend a few days at either the beginning or the end of your trip in Tokyo (and pay out of pocket for travel one-way to the airport). Then you could have a week to explore Kansai destinations like Kyoto and Osaka and travel onwards to Hiroshima and Miyajima via the castle town, Himeji. This is a classic first trip itinerary, returning to Tokyo on the last day of the pass.

On the other hand, with a couple more days and a 14-day pass, you could return to Tokyo via destinations such as Kanazawa, Nagano, or Takayama.

Keep in mind the difference in cost between a 7-day pass and a 14-day pass is ¥30,000 (or ¥40,000, for a Green Car pass). So don&#;t get a 14-day pass just to cover transport to and/or from Tokyo and Narita Airport. But do get a 14-day pass if you plan to be traveling some distance from Tokyo for more than a week.

Pro tip: For ideas on where to go and what to do with your JR Pass, check out this 7-day DIY rail itinerary that takes you from Tokyo to Niigata and then down to Kansai. Also this Northern Explorer option that sees you going deep into the heart of Tōhoku and Hokkaidō.

Can I stack JR passes?

Yes, this is possible. However the cost of two 7-day passes is the same as a 21-day pass (¥100,000).

You could also consider stacking regional rail passes, but this risks making things overly complicated. (With regional rail passes, you will need to disembark at the border of one region, cross to the next region, and then begin traveling on the next pass).

The countrywide JR Pass vs. regional rail passes

The classic Japan Rail Pass covers the whole JR rail network, offering maximum flexibility &#; you can literally travel from Tokyo to Hokkaidō to Kagoshima and back to Tokyo if you please. (A journey that, if you bought individual tickets for, would cost more than ¥100,000.)

However, there are many other rail passes that cover travel within specific regions; for example, there are rail passes just for travel around Hokkaidō, Shikoku, or Kyūshū that are less expensive than the countrywide JR Pass. These passes don&#;t, however, cover the cost of getting to and from Tokyo. So you&#;d have to work out if, after factoring in that cost, you&#;d still be saving money.

The only regional rail passes that covers travel from Tokyo are those offered by JR East. If your travel plans are limited to Tokyo and anywhere north and east of the capital, namely Tōhoku and Hokkaidō &#; and not destinations to the west, like Kyoto &#; then a regional rail pass from JR East might be a better choice that saves you money.

Is the JR Pass still worth it?

If you are planning a couple of inter-city return trips from Tokyo to places like Kyoto and Sendai, or one really long trip across the country, then the main JR Pass is worth getting.

The regular price (reserved seat during non-peak travel) for return travel between Tokyo and Kyoto is ¥28,340. Meanwhile, the regular round-trip price on the Shinkansen between Tokyo and Hiroshima alone is ¥38,880. So taking two trips like that would make the JR Pass worthwhile, even after October 1. For just a single trip, however, it&#;s probably not worth it.

If you plan to spend all of your trip in and around Tokyo (or Kansai, for that matter), then you almost certainly don&#;t need a national JR Pass. You might want a regional JR Pass or a single-use Shinkansen ticket.

You could also look at the prices of Japan&#;s low-cost airlines (more on non-rail travel later).

Are the views from the Shinkansen worth it?

While the Shinkansen may provide a better view of the country than you would get from the middle aisle of an airplane, it&#;s worth noting that large parts of the bullet train network are either underground or have sound barriers beside the tracks &#; so you might spend most of the journey dozing. You&#;ll still get plenty of glimpses of everyday Japan, though, and it&#;s possible to see Mount Fuji as you hurtle between Tokyo and Kyoto or Osaka (they&#;ll announce it).

Summary: What you need to remember when choosing a JR Pass

If you plan on taking the Shinkansen a lot, it&#;s a good idea to buy a rail pass. As we mentioned, the regular price for a return ticket on the Shinkansen between Tokyo and Hiroshima is around ¥38,000. Meanwhile, return journeys from Tokyo to Shin-Hakodate-Hokuto (Hakodate, in Hokkaidō) and Hakata (Fukuoka, in Kyūshū) cost the same: ¥46,860, nearly as much as a regular 7-day pass (which costs ¥50,000 from October 1).

However, if you&#;re only making one long-distance trip, a one-way Shinkansen ticket may work out to be cheaper. Use our Shinkansen fare calculator to help you figure out the best option for your travel plans.

Here&#;s a quick recap of the main tips:

  • DO buy a JR Pass if you&#;re planning a fair bit of inter-city travel. It&#;s best to plan your travels first, and then pick a pass accordingly.
  • DON&#;T buy a Japan Rail Pass if you&#;re just traveling around the Tokyo/Yokohama area. It&#;s cheaper to buy individual tickets or use a charged Pasmo/Suica card. And for exploring the greater Tokyo area, a Tokyo Wide Pass is likely better value.
  • Similarly, if you&#;re exploring Osaka, Kyoto, and surrounds, a regional pass like the Kansai Area Pass is probably a better deal.
  • To avoid any extra, unexpected travel costs, be sure to confirm the exact lines and services you can use, and read all the fine print.

Where can I buy the JR Pass?

There are currently two ways to buy a pass, both online:

For more information, please visit Russion Standard Rails.