Snippet to directly send an e-mail in Rails, without templates
ActionMailer::Base.mail(
from: "gamecreatre@example.com",
to: "receiver@example.com",
subject: "Sample Subject",
body: "Message Body"
).deliver
There are 6 posts tagged ruby on rails (this is page 1 of 2).
Snippet to directly send an e-mail in Rails, without templates
ActionMailer::Base.mail(
from: "gamecreatre@example.com",
to: "receiver@example.com",
subject: "Sample Subject",
body: "Message Body"
).deliver
The rails file cache is something that keeps growing.
Here are some 'handy' snippets.
Delete all files older then 7 days. (replace -delete with -print to test it)
find ./tmp/cache/ -type f -mtime +7 -delete
Delete all empty folders. (mindepth prevents the deletion of the root folder)
find ./tmp/cache/ -type d -empty -delete -mindepth 1
The whenever.rb
I use
job_type :command_in_path, "cd :path && :task :output"
every :day, at: "0:40" do
command_in_path "find ./tmp/cache/ -type f -mtime +7 -delete"
end
every :day, at: "1:10" do
command_in_path "find ./tmp/cache/ -type d -empty -delete -mindepth 1"
end
Just a short post for myself to remember the ActionMailer Preview functionality.
test/mailers/previews/mailer_preview.rb
class MailerPreview < ActionMailer::Preview def mailer_method_name TeamPersonMailer.mailer_method_name( email_method_argument ) end end
And view your preview emails at: http://localhost:3000/rails/mailers
Today I discovered my Ruby on Rails development environment database migrated with the wrong character encoding. It was using the MySQL default encoding latin1.
I didn't feel throwing my database away because it contains a lot of stuff.
I used the following snippet to convert all columns to utf8
ActiveRecord::Base.connection.tables.each do |table| ActiveRecord::Base.connection.execute( "ALTER TABLE `#{table}` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci") end
I'm working on a rails website that requires me to specify a class in an initializer.
config/initializers
spree.searcher_class = MySearcherClass
I'm currently developing this searcher class. Every time I change this class I get the following message:
A copy of MySearcherClass has been removed from the module tree but is still active
This sucks big time! Because I need to restart my rails application every time I change something.
My workaround for the moment is this:
spree.searcher_class = class.new do def new(*args,&block) return MySearcherClass.new( *args, &block ) end end end
I'm not very keen on this, but it does the trick for now :)