There have been many times that I noticed in rails project programmers using instance variables in model files. I was looking for why it was used, but I could not understand. For the context of things, I am reproducing a few code examples that look similar to what I saw.
This is in the controller directory.
class someController < ApplicationController def index @group = Group.find(params[:id]) @group.method_foo
This is in the model directory.
class someModel < ActiveRecord::Base // some relations and others defined def method_foo @method_variable ||= reference.first
What if I use only the local variable instested by the instance variable. Will this work fine? It would be helpful if someone would help me. Thanks.
source share