2017-05-01から1ヶ月間の記事一覧

過剰なルーティングのカスタマイズ

元記事はこちら 翻訳 Bad Smell map.resources :posts, :member => { :comments => :get, :create_comment => :post, :update_comment => :put, :delete_comment => :delete } Roy Fielding’*1の論文*2によると、リソースと、その状態を表すには、RESTful…

「パフォーマンス・マネジメント-問題解決のための行動分析学-」を読んだ

こちらのブログに触発されて、 blog.shibayu36.org パフォーマンス・マネジメント-問題解決のための行動分析学-を読んだ読書メモ。

RESTfulにするならデフォルトのルーティングを使わない

元記事はこちら 感想 内容がRails2の時代のものでRails5と書き方が大きく異なるので、翻訳は割愛。 RESTfulなルーティングを採用する場合は、余計なルーティングが生成されると、セキュリティリスクにもなるからやめましょうという主旨だと思う。 resources …

コーディング規約が浸透しない問題

コードレビュー、プルリクのタイミングなどでは、レビュアーの指摘は立ち位置をそのプルリク作者の思考地点に揃えるのが私は良いと思う。その前提が作れなさそうなら、実装方針を事前に揉むってことが必要だと思う。そういう流れが作れると割とスムーズにな…

入れ子モデルフォーム

元記事はこちら 翻訳 Bad Smell class Product < ActiveRecord::Base has_one :detail end class Detail < ActiveRecord::Base belongs_to :product end <% form_for :product do |f| %> <%= f.text_field :title %> <% fields_for :detail do |detail| %> <…

無駄に深いネスト

元記事はこちら 翻訳 Bad Smell map.resources :posts do |post| post.resources :comments do |comment| comment.resources :favorites end end <%= link_to post_comment_favorite_path(@post, @comment, @favorite) %> 3階層にネストしたルーティングは本…

model.collection_model_ids (多対多)

元記事はこちら 翻訳 Bad Smell class User < ActiveRecord::Base has_many :user_role_relationships has_many :roles, :through => :user_role_relationships end class UserRoleRelationship < ActiveRecord::Base belongs_to :user belongs_to :role end…

モデルのコールバックを使う

元記事はこちら 翻訳 Bad Smell <% form_for @post do |f| %> <%= f.text_field :content %> <%= check_box_tag 'auto_tagging' %> <% end %> class PostsController < ApplicationController def create @post = Post.new(params[:post]) if params[:auto_t…