Tuesday, April 28, 2009

Layout in actionmailer

By default mailer methods expects layout in view/layouts directory by the underscored version of the mailer class name.

If mailer class is like

class UserMailer <
ActionMailer::Base

def welcome_mail()

....
end

....
end


then the mailer layout name will be user_mailer.html.erb in view/layouts directory. The layout name needs to end in “_mailer” to be automatically recognized by mailer as a layout.

Content of user_mailer.html.erb should contain yield like the application layout. In this example the welcome_mail.html.erb will be rendered at yield position.

A different layout can also be set using

layout 'awesome' # it will use awesome.html.erb as the layout


class UserMailer < ActionMailer::Base

layout 'awesome'

....
end


Resource: http://guides.rubyonrails.org/action_mailer_basics.html

Wednesday, April 22, 2009

Error in loading mysql library in rails

Problem:

Error in loading mysql library

The specified module could not be found. - C:/ruby/lib/ruby/gems/1.8/gems/mysql-2.7.3-x86-mswin32/ext/mysql.so

Solution:

For this to work, you must have libmysql.dll in your PATH environmental variable. If you have MySQL installed locally,
just make sure that \bin is in your path. If you don't have MySQL installed locally, you can
install one or more of the MySQL tools, find the libmysql.dll included in their bin directory, and copy it to
the %SystemRoot%\System32 folder.

Reference: RubyInstallDirectory/lib/ruby/gems/1.8/gems/mysql-2.7.3-x86-mswin32/README