w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Sharing variable's data across controller method via before/after filters or the session hash. Which way is better if filters allow this?

The short answer is yes. Pretty popular for loading models. For example:

class UsersController < ApplicationController
  before_filter :load_user

  def show
  end

  private

  def load_user
    @user = User.find(params[:id])
  end
end

@user is now set and accessible in your view. You can ripple that across other methods or use 'only' or 'except' to filter which of them they apply to.





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.