Use the same template for multiple ActionMailer actions
One option is to use partials. Or you can set the @template
field to the name of another action:
class Mailer < ActionMailer::Base
def foo
subject "Hello World"
end
def bar
subject "Hello Universe"
@template = 'foo'
end
end
Related cards:
How to use Parallel to speed up building the same html partial multiple times (for different data)
The parallel-gem is quite easy to use and can speed up rendering time if you want to render the same partial multiple times (e.g. for rendering long lists of things).
If your parallelized code talks to the da...
Howto respond html or json in the same controller action with Rails 2
Code snippet tested with Rails 2.3
def index
# ...
if request.xhr?
html = render_to_string(:partial => "list", :layout => false)
respond_to do |format|
format.html { render :text => html }
format.json {...
Use different CSS depending on whether elements render on the same line or multiple lines
You will find this useful when creating responsive designs that work well on small screens.
The attached Javascript gives a container different CSS classes (single_line
or multiple_lines
) depending on whether its children render on one line o...
Use the same translations for ActiveRecord and ActiveModel
ActiveRecord translations live in locale.activerecord
. ActiveModel translations live in locale.activemodel
. To use the same translations for both, use YAML references with &
and *
:
de:
models: &models
user: 'Benutzer'
attrib...
Why has_many :through associations can return the same record multiple times
An association defined with has_many :through
will return the same record multiple times if multiple join models for the same record exist (a n:m relation). To prevent this, you need to add ->{ uniq }
as second argument to has_many
(below Ra...
VCR fails if the same request is triggered multiple times
Same requests are recorded only once in vcr. Replaying a test fails, if you trigger the same request multiple times. The error message is somehow confusing, as your cassette contains the request:
`An HTTP request has...
Using multiple MySQL versions on the same linux machine using docker
We had a card that described how to install multiple mysql versions using mysql-sandbox
. Nowadays with the wide adoption of docker it might be easier to u...
Installing multiple MySQL versions on the same Linux with mysql-sandbox
Ubuntu has a package mysql-sandbox
that lets you install multiple MySQL versions into your user home:
- Install
mysql-sandbox
sudo apt install mysql-sandbox
- Download the version of MySQL you want to use from mysql.com:
<https://...
Working on the Linux command line: How to use bookmarks for directories
Bookmarks for directories will be most helpful if you are forced to work in deeply nested projects. Then it's really helpful!
This makes use of the CDPATH
variable. Similar to the PATH
variable, which holds the list of directories which are s...
Run multiple local webricks at the same time using different ports
If you specify different ports, you can run multiple local webricks with rails server --port=300X
at the same time.