Hard work by INTERNET

ベンチャーで働くひとりぼっちWEB開発者が頑張るブログ

number_to_currencyの出力に半角スペースではなくnbspを使ってくれ

github.com

半角スペースを含む€のような通貨だと意図しない改行が発生してしまう、という文脈みたい。 ちなみに、CSSにはスペースなどの単語の区切りで改行するようになっている。

今までは半角スペースを置換するパッチが活躍していたらしい。

HTMLEntities.new.encode(Class.new.extend(ActionView::Helpers::NumberHelper).number_to_currency(12, locale: 'de').gsub(' ',"\u00A0"), :named)
=> "12,00 €"
  • be addressed
    • 問題に取り組む

ActiveRecord#valid?はinteger型上限バリデーションを含めるべき rails/rails#37256

ActiveRecord valid? should includes ActiveModel validation for integer type column · Issue #37256 · rails/rails · GitHub

validationを設定していないモデルのテーブルにint(11)型で定義したカラムにint(11)を超える値を設定すると、バリデーションエラーが起きないで、例外が投げられる挙動について書かかれたissue。

このissueについたコメントは、int(11)の範囲内を保証するvalidationつければいいんじゃねえの?という真っ当なコメント。 このコメントに対して、validationを設定したら他のvalidationとレイヤーが違うでしょ。だからデフォルトのvalidationに追加が必要だと思う、と返信をした。

所感

デフォルトバリデーションが具体的にどんな振る舞いをするのかはわからないので、それ次第ですが、 想定外の値が入ってくることは不具合の可能性が高いので、validationをすっ飛ばして例外を投げている現在の実装に対して不自然さは特に感じない。

Migrationが2回走る #37225

Migration running twice #37225

Migration running twice · Issue #37225 · rails/rails · GitHub

質問1

railsコマンドを実行すると2回実行してしまう。一体何が起きているんですか? (本文に再現コードあり)

回答1

This file does not have the migration code in an up method.

そのファイルにはマイグレーションファイルの中にupメソッドがない。

I would venture a guess that the file is getting run multiple times and running the defined migrations each time

そのファイルは複数回実行されて、マイグレーションの定義を毎回実行する、と検討をつけるでしょう。

The syntax highlighting is a dead giveaway, watch out for that 😎

シンタックスハイライトは死んでる。注意してね。

質問2

Yeah, that would be it. Why isn't that an error? "Migration has no up or change method"

おおおお、たぶんそれっぽい。なぜマイグレーションにup か changeが無い時にエラーが起きないの?

回答3

Yeah it's just a ruby file and those methods (create_table, add_index, etc) are class methods.

それはただのrubyファイルであり、クラスメソッドです。

It's definitely a gotcha but unfortunately it's valid ruby.

たしかに落とし穴(?)しかし、残念ながら正しいRubyです。

When you require the file, it will perform the method calls just as directed.

そのファイルが必要な時、そのメソッドを直接実行するでしょう。

Also, up, down, and change are all intentionally optional.

また、up, down, changeはすべて意図的にオプションです。

This allows you to do things like comment out all your methods to force a migration to be marked as ran.

あなたのメソッドをコメントアウトするように、マイグレーションを強制的にマークすることができるようになります。

4.2の互換性を断つなら、down, up, change以外でのDSLをブロックできる、ということが書いていた。 おわり。

Rails migration guide does not mention the removal of render :text #37145

github.com

render :text が削除されたことがアップグレード移行ガイドにに書かれていない、という指摘のissueだ。

本文

render :text was removed in 5.1 but it is not mentioned in the upgrading guide for 5.1.

render :textが5.1から削除されたが、アップグレード移行ガイドに触れられていない。

It is mentioned that it is discouraged under the 4.0 to 4.1 upgrade but it would be useful to see it mentioned on the release it was removed from.

4.0から4.1のアップグレードで非推奨だと記載していたが、削除されたリリースで言及されていると便利です。

なお、本issueへのプルリクが作られているけど、本件についてリリースノートで書かれているよ、というツッコミがきていた。

github.com

ActiveRecord::Base#dup が動的属性を含めてくれない(does not include dynamic attributes) #34823

github.com

本文

rails4.2.xでは、 lib/active_record/core.rb#initialize_dup が正しく複製してくれるけれども、rails5.2ではpullするだけ MyModel._default_attributes によって、すでに複製したものを削除する。

Yes this still occurs on 5-2-stable. I've already included details on where the offending code is.. Right now we have resorted to manually handling duping because of the broken rails AR code.

rails5.2のステイブルではまだ起きている。問題のコードの場所は >>1にすでに含めています。 ActiveRecordのコードが壊れたことによって、私達は手動での複製処理に頼っています。

Since you know where the offending code is, what do you thing about opening a PR?

問題のコードをあなたは知っているので、プルリクエストを開くことについてどう思っていますか?

I can do that sometime next week.

来週なにかできるよ。

以降音沙汰なし。

railsのアンダースコアに変換するメソッドの戻り値がおかしいんけど

github.com String inflection method underscore giving wrong output #37163

質問

アンダースコアライズする文字列変換文字列のアウトプットがおかしいんだが?

Open up rails console and type - "ActLikeStar".underscore gives you 'act_like_star' which is correct.

rals consoleでこれを入力すると、"ActLikeStar".underscore 'act_like_star' になる。これは正しい。

Now Type - "AB".undescore . which gives you 'ab' which seems to be incorrect.

次は "AB".undescore .を入れると 'ab' になる。おかしい。 a_b のような出力を与えるべきだ。 It should give output like this 'a_b'

回答

これは期待通りの振る舞いです。頭字語の見た目がナイスになります。 あなたは他の変換例をもっと見ることができるよ。

github.com

回答2

先の人が回答したように想定した振る舞いです。 全角だけで表現している場合は、ほとんどのケースではアンダースコアを含めないことを期待している。

おわり