Skip to content

Instantly share code, notes, and snippets.

@tkawa
Last active December 18, 2015 15:28
Show Gist options
  • Save tkawa/5804142 to your computer and use it in GitHub Desktop.
Save tkawa/5804142 to your computer and use it in GitHub Desktop.
# config/routes.rb
# question and answers that the user has
# /users/:user_id/questions
# /users/:user_id/answers
resources :users do
resources :questions
resources :answers
end
# app/controllers/concerns/users_resource.rb
module UsersResource
extend ActiveSupport::Concern
included do
helper_method :owner
hide_action :owner
end
private
def owner
@_owner ||=
User.where(id: params[:user_id]).first
end
end
@tkawa
Copy link
Author

tkawa commented Sep 17, 2013

インスタンス変数よりメソッドのほうが自然、ということですかねぇ。僕もどちらかというとメソッドのほうが好きかなぁ。
hide_actionは要らないんじゃないかと思いますがよくわかりません…。ひょっとするとinclude先では扱いが違うのかも。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment