I'm trying to create my first Rails plugin and am having some troubles leveraging ActionMailer in it. The plugin just collects user feedback and emails it off a given address so in terms of functionality it's not too complicated...
All the functionality was working perfectly in my original application until I decided to pluginise this stuff. I've been following the railsguide on creating a plugin as much as possible and you can find my entire plugin's source here:
http://github.com/gshankar/rocket_feedback
Though I'm pretty sure the problem is in one of these files:
1- The file that loads everything in: rocket_feedback/lib/rocket_feedback.rb
require 'rocket_feedback/routing'
require 'action_mailer'
%w{ models controllers }.each do |dir|
path = File.join(File.dirname(__FILE__), 'app', dir)
$LOAD_PATH << path
ActiveSupport::Dependencies.load_paths << path
ActiveSupport::Dependencies.load_once_paths.delete(path)
end
2- The controller which calls the deliver_feedback method rocket_feedback/lib/app/controllers/rocket_feedback_controller.rb
class RocketFeedbackController < ApplicationController
#Email method for feedback
def send_feedback
subject = params["subject"]
from = params["email"]
feedback = params["feedback"]
RocketFeedback::deliver_feedback(from, subject, feedback)
respond_to do |format|
format.js { render :text => ''}
end
end
end
3- The model (which inherits from ActionMailer)
class RocketFeedback < ActionMailer::Base
default_url_options[:host] = HOST
def feedback(from, subject, feedback)
@subject = "Feedback: #{subject}"
@subject_for_message = subject
@recipients = '[email protected]'
@from = from
@sent_on = Time.now
@sent_at = Time.now.strftime("%d/%m/%Y, %I:%M:%S %p").to_s
@body["sent_at"] = @sent_at
@body["from"] = from
@body["feedback"] = feedback
@body["subject"] = @subject_for_message
@headers = {}
end
end
The only clue I have is this error message when I try and send feedback via the plugin:
NoMethodError (undefined method `deliver_feedback' for RocketFeedback:Module):
Thanks in advance for you help! (And please feel free to critque my plugin's structure, it's my first attempt so I'm sure I've done all kinds of things wrong...)