2017-04-01から1ヶ月間の記事一覧
元記事はこちら 翻訳 Bad Smell class InvoicesController < ApplicationController def create @invoice = Invoice.new(params[:invoice]) @invoice.address = current_user.address @invoice.phone = current_user.phone @invoice.vip = (@invoice.amount …
元記事はこちら 翻訳 Bad Smell class PostsController < ApplicationController def publish @post = Post.find(params[:id]) @post.update_attribute(:is_published, true) @post.approved_by = current_user if @post.created_at > Time.now - 7.days @po…
元記事はこちら 翻訳 Bad Smell <% form_for @user do |f| %> <%= text_field_tag :full_name %> <% end %> class UsersController < ApplicationController def create @user = User.new(params[:user]) @user.first_name = params([:full_name]).split(' '…
元記事はこちら 翻訳 オブジェクトのオーナーとcurrent_userを比較することで、アクセス権をチェックしたいとおもったら、そんな冗長でイケてない書き方はせずに、スコープをつかてアクセスしましょう。 Bad Smell class PostsController < ApplicationContr…
元記事はこちら 翻訳 Bad Smell class PostsController < ApplicationController def create @post = Post.new(params[:post]) @post.user_id = current_user.id @post.save end end この例では、user_idは明らかに@postに割り当てられます。大きな問題には…
元記事はこちら 翻訳する BadSmell class PostsController < ApplicationController def index @published_posts = Post.find(:all, :conditions => { :state => 'published' }, :limit => 10, :order => 'created_at desc') @draft_posts = Post.find(:all,…
転職してPHP->Ruby(Rails)に宗旨替えしました。 Railsの書き方にようやく慣れてきたものの、まだまだ書き方で指摘されることが多いので、 RailsのBestPracticeを読んで勉強することにしました。 1日1本目標に読んでいく。