How can I access a controller's instance variable inside of a model?
In this example, I want to access the instance variable @user
inside of the model.
Post Controller
class PostController < ApplicationController
def destroy
@user = User.find(params[:user_id])
post = Post.find(params[:id])
end
end
Post Model
class Post < ActiveRecord::Base
belongs_to :user
before_destroy :check_if_owned_by_user
if self.user != @user
return false
end
end
end