“...I've been working since 2008 with Ruby / Ruby on Rails, love a bit of Elixir / Phoenix and learning Rust.
I also poke through other people's code and make PRs for OpenSource Ruby projects that sometimes make it
Currently working for GenieBelt who are based in Copenhagen, Denmark ...”
describe FacebookPublisher do
class Facebooker::Service
def post(*args)
return "1"
end
end
it "just should ok" do
Facebooker::Session.create.<some method thingy>
end
end
I wanted to be able to send out a mail from a controller but also validate the incoming args in a clean way. Like so…
class MessagesController < ActionController::Base
def deliver
@message = Message.build(params[:message])
if @message.deliver
redirect_to home_path
else
render :action
end
end
ActionMailer::Base hides the initialize methods in method_missing and most of the time you are calling ActionMailer::Base.deliver_mymail(args). This allows you to specify all of the standard actionmailer settings in Message.build and return a Message object.
class Message < ActionMailer::Base
include Validatable
validates_presence_of :from, :body
def self.build(args = {})
new('default', args)
end
def self.action_mailer_methods
return [
:bcc,
:body,
:cc,
:charset,
:content_type,
:from,
:reply_to,
:headers,
:implicit_parts_order,
:mime_version,
:recipients,
:sent_on,
:subject,
:template
]
end
def default(args)
new_args = args.clone
new_args.each do |k,v|
if self.class.action_mailer_methods.include?(k)
send(k, new_args.delete(k))
end
end
if body.kind_of?(Hash)
@body.merge!(new_args)
end
end
def deliver
if self.valid?
return deliver!
else
return false
end
end
end
I found this little gem in a bog standard boring, run of the mill newsagents in Berlin, Zoologischer Garten. Perhaps Germany is more tech friendly but having monthly Ruby on Rails, PHP, .Net and Java monthlies is is quite crazy for what would be a small readership.
Hi dean,
First of all great work. I have a problem when I use your script inside a frame (ugly, I know). I get a permission denied on ‘if(/ie7_off/.test(top.location.search)||k<5)’.
Any thoughts on a quick fix?
Thanks, Ronald Moolenaar