Hi, I have a simple module for adding the current user to a newly created object:
module AttachUsers
def create_with_author(author, params)
created = new(params)
created.author = author
created.save
created
end
def create_with_author_and_editor(author, params)
created = new(params)
created.author = author
created.lasteditor = author
created.save
created
end
end
The module is saved as attach_users.rb directly under the lib directory.
I've tried to use this module with two models so far. It worked fine with the first (comment) model, however the second (page) returns the error message
undefined method `create_with_author_and_editor'
I have the following at the top of each of my models:
extend AttachUsers
I am using it in the comments controller like this:
@comment = @post.comments.create_with_author(current_user, params[:comment])
And in the pages controller like this:
@page = Page.new
respond_to do |format|
if @page.create_with_author_and_editor(current_user, params[:page])
Can anyone see why it might not be working correctly? This is the first time I've tried to use modules, sorry if it's something obvious.
Any advice appreciated.
Thanks