I have Module.rb file with code
module Finder
module InstanceMethods
def my_func
@post = Post.find(params[:id])
end
end
def self.included(base)
base.send :include, InstanceMethods
base.before_filter :my_func
end
end
And Controller with code
include Finder
But my app crashes with code
undefined method `name' for nil:NilClass
Extracted source (around line #5):
2:
3: <p>
4: <b>Name:</b>
5: <%= @post.name %>
6: </p>
7:
8: <p>
It seems like @post didn’t working. Whats wrong?
I did it.
My module didn’t work ’cause I didn’t add line
into application.rb file.After that, I made my task working with this code: