我有带有代码的 Module.rb 文件
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
和带有代码的控制器
include Finder
但是我的应用程序因代码而崩溃
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>
@post 似乎不起作用。怎么了?