2017-03-13 5 views
1

ユーザーが行っているアクションをコントローラー内のメソッドに渡すにはどうすればいいですか?例えばコントローラーカスタムコントローラーメソッドにアクションを渡す - ROR

before_action :require_login, only: [:new, :create, :edit, :update, :destroy] 

ユーザーが使用しようとする場合:私はこのような何か言いたい私の方法でログインする前に編集アクション:

def require_login 
    unless current_user 
    if (:edit action) 
     flash[:alert] = "You must log in before you are able to edit foo" 
    end 
    end 
end 

答えて

1

は何params[:action]です後で?

flash[:alert] = "You must log in before you are able to #{params[:action]} foo" 

params[:controller]

利用可能であるべきです
関連する問題